Code Monkey home page Code Monkey logo

Comments (6)

pedroapfilho avatar pedroapfilho commented on June 13, 2024 1

Hello @gregjopa sorry for not providing the example right away, I was in the middle of the investigation, and just thought about it.

What we actually could do is say to the users to:

If you run the `resetOptions` inside a `useEffect` call, you must add an if statement inside to check if the previous script was already resolved, because this can cause a race-condition and make the call not very reliable.

from react-paypal-js.

gregjopa avatar gregjopa commented on June 13, 2024

Hi @pedroapfilho can you provide a full example of the problem? Perhaps you can update the Storybook Currency example to demostrate the issue: https://paypal.github.io/react-paypal-js/iframe.html?id=example-usepaypalscriptreducer--currency&viewMode=story.

from react-paypal-js.

gregjopa avatar gregjopa commented on June 13, 2024

The other thing that comes to mind is to add a check to make sure the script is finished loading before dispatching the resetOptions action. I'm wondering if the problem is the script is still loading when you try to dispatch this event so it doesn't get picked up properly because of this code: https://github.com/paypal/react-paypal-js/blob/main/src/ScriptContext.tsx#L101

If so, adding this check should resolve the issue.

if (isResolved && selectedCurrency !== defaultCurrency) {
    paypalDispatch({
    type: "resetOptions",
    value: {
        ...options,
        currency: selectedCurrency,
    },
    });
}

from react-paypal-js.

pedroapfilho avatar pedroapfilho commented on June 13, 2024

I'll create an example on the storybook today, stay tuned for the PR.

from react-paypal-js.

gregjopa avatar gregjopa commented on June 13, 2024

Do you think this feature request would help your use case with setting currency later on after defining the Script Provider? #89.

from react-paypal-js.

pedroapfilho avatar pedroapfilho commented on June 13, 2024

Yes and no.

It could help if we wanted to lazy load the component until we have the currency figured out, or we can basically trigger it after isResolved, just like you added on your comment.

from react-paypal-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.