Stop component re-rendering with useSelector#19
Open
GeraldHost wants to merge 4 commits intoweb-ridge:mainfrom
Open
Stop component re-rendering with useSelector#19GeraldHost wants to merge 4 commits intoweb-ridge:mainfrom
GeraldHost wants to merge 4 commits intoweb-ridge:mainfrom
Conversation
Member
|
Hey very cool PR, I forgot about it: BTW esm build etc are very nice |
Author
|
@RichardLindhout let me check, I also just realised I'm committing the build which is not ideal so will sort that too. |
gaberogan
reviewed
Oct 3, 2024
Comment on lines
+111
to
+116
| const [l, s] = R.useState<TSelected>(); | ||
| sub((nv) => { | ||
| const v = se(nv); | ||
| if (!eq(v, l)) s(v); | ||
| }); | ||
| return l; |
There was a problem hiding this comment.
Looks like it's not initialized properly. Recommend updating this useState(() => selector(v)); and making a new PR since the code has divergged.
function useSelector(selector, comparator = equ) {
const [state, setState] = useState(() => selector(v));
subscribe(() => {
const selectedValue = selector(v);
if (!comparator(selectedValue, state)) setState(selectedValue);
});
return state;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As per this ticket: #18
I've tested this solution and it seems to fix the problem with the re-renders.