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
275 stars 81 forks source link

Makes PayPalButton safe for SSR #8

Closed kadams54 closed 5 years ago

kadams54 commented 5 years ago

If the component renders on the server, the old code evals !isSdkReady, finds it to be true and then because of the && it also has to check if window.paypal is true. That fails because window is undefined on the server. Switching to an || means that as soon as !isSdkReady evaluates to true, it doesn't need to evaluation the rest of the statement and null is returned.

slk333 commented 5 years ago

why is this PR not merged yet? @Luehang

slk333 commented 5 years ago

@kadams54 would you know any workaround? Because of this, I cannot deploy to Netlify. Imagine if this npm became unmaintained, we would need to create a new npm package?

Luehang commented 5 years ago

The following changes is unstable for some of the use cases.

Luehang commented 5 years ago

Next update will have SSR support. The update release will be soon after thorough testing with many use cases.

slk333 commented 5 years ago

I found a workaround for the SSR: use this: https://github.com/jamiebuilds/react-loadable to wrap the component. It builds fine now.

Luehang commented 5 years ago

Hi,

This pull request doesn't correctly solve all of the given test use cases.

There has been a new update. 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