-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add deps
to useSelector
to allow controlling stability of selector
#1251
add deps
to useSelector
to allow controlling stability of selector
#1251
Conversation
}) | ||
|
||
describe('edge cases', () => { | ||
it('ignores transient errors in selector (e.g. due to stale props)', () => { | ||
// TODO Not sure this test is really testing what we want. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was correct in what it tested. In fact, it failing showed an error in the implementation.
Deploy preview for react-redux-docs ready! Built with commit 143ca4e |
|
||
let selectedState = undefined | ||
|
||
try { | ||
selectedState = latestSelector.current(store.getState()) | ||
selectedState = memoizedSelector(store.getState()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using latestSelector.current
was wrong, since it was a stale selector. This change fixes that issue, which makes the test for stale props succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, nice catch :)
If no dependency array is passed what happens? |
@Dudeonyx : the latest passed-in selector should get used, instead of a previous one. |
LGTM. I'll try to get alpha.1 published shortly. |
#1251) * fix stale selector issue * add `deps` to `useSelector` to allow controlling stability of selector
#1251) * fix stale selector issue * add `deps` to `useSelector` to allow controlling stability of selector
reduxjs#1251) * fix stale selector issue * add `deps` to `useSelector` to allow controlling stability of selector
This PR adds a
deps
parameter touseSelector
as discussed here.It also fixes an issue with staleness of the selector.