Skip to content

Conversation

GeraldHost
Copy link

As per this ticket: #18

I've tested this solution and it seems to fix the problem with the re-renders.

@RichardLindhout
Copy link
Member

Hey very cool PR, I forgot about it:
Will this still work:
#13

BTW esm build etc are very nice

@GeraldHost
Copy link
Author

@RichardLindhout let me check, I also just realised I'm committing the build which is not ideal so will sort that too.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants