Luehang / react-paypal-button-v2

An easy and simple to use React button component to implement PayPal Checkout with Smart Payment Buttons V2 (Version 2).
https://luehangs.site/lue_hang/projects/react-paypal-button-v2
MIT License
274 stars 81 forks source link

ReferenceError: window is not defined #13

Closed secretlifeof closed 5 years ago

secretlifeof commented 5 years ago

Thank you very much for taking the time to write this package.

I am getting

ReferenceError: window is not defined

using this with SSR (Razzle)

Have you tested this with SSR? Please let me know if you want some more information on my setup.

liesislukas commented 5 years ago

just wanted to open issue about this :)

FYI simple work-around is to have it included like this:

on top of component file:

let PayPalButton = null;
if (typeof window !== 'undefined') {
  PayPalButton = require('react-paypal-button-v2').PayPalButton;
}

inside jsx:

          {PayPalButton ? <PayPalButton/> : null}

but i hope it will be updated to handle SSR w/o any extra stuff.

Luehang commented 5 years ago

Hi,

Version 2.4.0 will support SSR.

:large_blue_diamond: Install

$ npm install react-paypal-button-v2@2.4.0 --save

or

$ yarn add react-paypal-button-v2@2.4.0