Redux-Session | Redux middleware for automatic setting | Frontend Framework library
kandi X-RAY | Redux-Session Summary
kandi X-RAY | Redux-Session Summary
It's often preferable for part of a user's state to be preserved even after the browser tab has been closed or when moving from one route to another. There are mechanisms and techniques for persisting this data across usage sessions. Two common examples would be localStorage and cookies. While the interfaces for these tools are fairly straight forward, it often involves littering your code with statements for managing this additional form of state. With Redux, we can keep our state managed in one place and allow "middleware" to subscribe to state changes or submit their own. This pattern makes it relatively easy to save and reload state from a storage mechanism without adding tightly coupled storage operations throughout our code.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Redux-Session
Redux-Session Key Features
Redux-Session Examples and Code Snippets
Community Discussions
Trending Discussions on Redux-Session
QUESTION
I use redux-sessionstorage to store a subset of my app's state to session storage. Part of that state indicates whether certain panels in the UI are expanded or collapsed (visible or hidden).
I have a sample app reproducing exactly this: https://github.com/shawninder/sessionstorage-bug
See the readme for complete reproduction steps.
Also hosted online here (give it a moment to unfreeze)
The problem happens when I reload the page. redux-sessionstorage correctly restores the previous state from sessionstorage and triggers a render, yet the style attribute I'm using to do the hiding and showing is not updated.
In other words, this works as expected:
...ANSWER
Answered 2019-Mar-22 at 18:18@lecstor pointed to the right thread about this issue.
This is a thing with Server Side Rendering (SSR). The workaround Dan Abramov described on this comment solved the issue.
You're using Next.js for SSR. When running your project on dev
mode, you can see the following error message on Chrome console, after pressing Toggle to true and reloading:
Warning: Text content did not match. Server: "false" Client: "true"
Since Next doesn't know anything about the saved state on the client side, it always returns app.showNotice
to false
. You can also check the returned content for GET localhost
on Chrome Network Tab.
Apparently Next.js
tries to merge the content returned from the server and the one rendered locally, but fails to merge the style. Apparently, it's an expected behaviour on Next and also on React 16 SSR, that you can overcome by triggering a second render()
or doing the implementation below.
QUESTION
I am trying to use the redux-session library to store my apps state through page refreshes, however this is not working.
I have looked at the session object and it is getting the data, but populating quite slowly and endlessly nesting itself ie:
session: { myobject: {}, session: { myobject: {data:2}, session: { myobject: {data:2}, session: {...
By adding
...ANSWER
Answered 2017-Dec-04 at 08:10no idea why state.toJS().myobject is {}
Fast code analysis shows that nothing had been restored from localStorage
when redux
store is created. At every code points initialState
is always {}
, so it's expected that store will have empty object.
Maybe following code should be refactored to check localStorage
state and maybe load or merge with it. Also, there is no preloaded state from server side.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Redux-Session
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page