I have a multi-step form application, and I'm struggling with getting my head around how I can save my redux state and replay it after a refresh for example? Going back/forward in the app works as expected, but after a browser refresh, my previous state is empty. Ideally I'd like to be able to save prior state in session storage relating to a path, so that I can replay later, but I'm not seeing how I can do that easily. Has anyone done anything like this and can provide some pointers? Thanks.
相关问题
- How to toggle on Order in ReactJS
- Refreshing page gives Cannot GET /page_url in reac
- Adding a timeout to a render function in ReactJS
- React Native Inline style for multiple Text in sin
- Issue with React.PropTypes.func.isRequired
相关文章
- Cannot find module 'redux' 怎么解决?
- Why would we use useEffect without a dependency ar
- Is it possible to get ref of props.children?
- Stateless function components cannot be given refs
- React testing library: Test attribute / prop
- React/JestJS/Enzyme: How to test for ref function?
- Material-UI [v0.x] RaisedButton on hover styles
- Remove expo from react native
It looks like you're trying to use a single-page app framework within a multiple-page context. To make the two play nicer together, you could look into making your own middleware that synchronizes state to and from
localStorage
to create an app that appears to not have lost any state after a refresh/page navigation.localStorageLoad
) and end (localStorageDump
) of thecreateStoreWithMiddleware
function creation (right beforeredux-logger
):The
localStorageLoad
would handle theINIT
action and dispatch some sort ofSET_STATE
action, which would contain a payload with the state that was previously saved inlocalStorage
.Then, add a reducer which replaces the state with that payload, effectively rebooting the app as it was previously.
localStorageDump
middleware that comes at the end of the chain that saves each reduced state object intolocalStorage
. Something like this:Just an idea, haven't actually tried it. Hope that helps get you started towards a solution.
You can't store state on refresh this is normal. Typically you store these inside cookies or web storage.
Redux:
Form
component, usecomponentWillMount
method to read thelocalstorage
anddispatch
the data to a reducerIf you use redux to store form data dispatch the properties of localstorage.
If not read the localstorage inside the
Form
component and set the initial values.Hope this helps !