selector in useSelector called one more time after forceUpdate inside hook
See original GitHub issueWhat is the current behavior?
When state changed, selector recomputes, and value sets into latestSelectedState. Component will re-render, and selector recomputes again, but its value already in latestSelectedState.current
(selector is arrow function - const data = useSelector((state) => state.data);
)
What is the expected behavior?
Selector recomputes once
I can open PR to fix this, but I don’t know, may be selector specially calls twice for some reasons
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
useSelector() not re-rendering component on update
A useEffect hook with dependency array [] will only run one time when the component is first mounted. Your fetch actions depend on...
Read more >How useSelector can trigger an update only when we want ...
The useSelector hook from react-redux doesn't have this issue — components only re-render when their selected piece of state changes, even when ...
Read more >Hooks FAQ
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. This page...
Read more >Hooks
You may call useSelector() multiple times within a single function component. Each call to useSelector() creates an individual subscription to ...
Read more >useSelector with equality check still triggers useEffect #1381
useSelector is a function that returns one value, so we do a reference equality comparison to see if that one value has changed...
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 Free
Top 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
@phantomcosmonaut no, that shouldn’t have anything to do with this issue. This is about a selector re-running when the component is already rendering. What you’re describing is a store subscription causing a component to render in the first place.
If you’re seeing problems with React-Redux and Suspense, please file a new issue with a reproduction so we can look into it.
Hey, I was using Suspense and a custom hook to render components asynchronously with async data fetching redux actions and I seem to have run into an issue directly related to this thread. I get the error
Cannot update a component ('IdentityVerificationScreen') while rendering a different component ('RenderSuspender'). To locate the bad setState() call inside 'RenderSuspender'
which takes me to theforceRender
call fromuseSelector
hook. Do you think the update in 7.2.4 will solve this issue and when can I expect to see the new version released? Thanks!