user3523091
user3523091

Reputation: 945

Stripe redirect to my SPA loses all state

After submitting the Stripe payment form (hosted on their server), a redirect happens to my React SPA that launched it. It reloads the entire SPA, losing all state. I'm using React Router and the return address I've set up is a particular Route. How can I prevent it from losing all state?

The same problem happens when clicking the Cancel in the form, or hitting the back button.

Sure I can store the state on the server before launching the payments page, and then retrieving it later, but that's a lot of extra work.

I think this must be a common problem with SPAs, but I haven't found an easy solution.

Upvotes: 2

Views: 801

Answers (1)

Nolan H
Nolan H

Reputation: 7459

If your state is only in memory, I would expect to lose it. To keep it around, you need to save it somewhere to be reloaded when the user comes back to your site. Local storage is a good option.

If you are using redux for state management, for example, you can use redux-persist to save & load your redux store in local storage.

https://www.npmjs.com/package/redux-persist

Upvotes: 1

Related Questions