Stale props issue in selector API
See original GitHub issueThanks so much to https://github.com/reduxjs/react-redux/issues/1179#issuecomment-483617153, it explains better to understand.
So, as long as we use useReduxState()
, we are safe, but with selectors there could be inconsistencies. In our case, it’s useReduxSelectors()
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Hooks - React Redux
Hooks. React's new "hooks" APIs give function components the ability to use local component state, execute side effects, and more.
Read more >Dealing With Stale Props and States in React's Functional ...
Long story short: it's when code that is executed asynchronously has a reference to a prop or state that is no longer fresh,...
Read more >Stale props and zombie children in Redux | Kai Hao
The problem Stale props means any case where: a selector function relies on this component's props to extract data. a parent component would...
Read more >React/Redux, useEffect/useSelector, stale closures and event ...
A working solution is to pass it the selector as a dependency – however, this results in the listener being removed/re-added every time...
Read more >Using the React-Redux Hooks API to Manipulate Store State
Stale props mean that a selector function relies on a component's props to extract data, a parent component would re-render and pass down ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess the discussion in https://github.com/reduxjs/react-redux/issues/1252 explains it.
So, in conclusion, our
useReduxState
doesn’t have stale props issue because it doesn’t remember anything, anduseReduxSelectors
has the issue as well as the official react-redux hooks (and probably all other unofficial hooks) which we’d basically live with as a limitation.@faceyspacey You asked somewhere for the clarification, here it is.
This totally explains. Thanks a lot.
While you are here, do you think react-redux v7 accepts this stale props issue as a limitation of hooks api? I think your proposal is the best so far and it’s silly to introduce hoc to solve the stale props issue. It would have been nice if the state context (aka v6) were possible, but it not likely to happen in the foreseeable future.