Skip to content

Conversation

@captbaritone
Copy link
Collaborator

@captbaritone captbaritone commented Nov 1, 2025

It is a tricky problem to ensure we:

  • Always update our subscription to use the new selector while also...
  • Avoiding a double render when the selector changes and still...
  • Derive the correct new value from the larger state atom when the selector changes

This approach augments the state we track in the hook to include both the current state value as well as the selector used to read that state value. If the current selector does not match the value used to compute the current state, we derive a new state in render and then re-trigger the useLayoutEffect which can handle fixups and re-creating the subscription with the new selector.

In theory I believe this same approach should be possible to support allowing the store to change as well.

Fixes #13

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 1, 2025

npm i https://pkg.pr.new/thejustinwalsh/react-concurrent-store@18

commit: ebc1c69

@captbaritone captbaritone marked this pull request as ready for review November 1, 2025 05:31
@captbaritone captbaritone merged commit d65794c into thejustinwalsh:main Nov 1, 2025
3 checks passed
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.

[Experimental] Selector changes are not supported

1 participant