-
Notifications
You must be signed in to change notification settings - Fork 8
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
Prefer using react api for useProperty hook #26
Comments
Hey @PalmZE, thanks for such a detailed issue! So, correct me if I'm wrong, the issue is that during rendering of list items that reference list values in Properties by index, we can get out of sync with the data because this list item component is not unmount in time, right? This happens due to asynchronous nature of the renderer, right? Then I would expect such components reading the data by index to check whether the item is not Originally, Ok, now speaking about Thanks for opening the issue and let's continue the discussion here. |
I thought a bit more about the issue, and I agree.
Existing bindings are working fine. This is an approach similar to other libraries (mobx, effector, etc). I created this issue to discuss the possibility of using I'll test Conclusion: I have nothing to add, feel free to close this issue. |
Thanks for the feedback @PalmZE. Closing. |
Hey, @raveclassic!
Intro
I'm developing a chat. It means that I need to subscribe to properties in leaves (messages, etc.) so only necessary parts re-render.
I was testing performance and noticed that old version of
useProperty
lost updates (new works fine). This led me to some research. Results are below.1 React-way to subscribe to mutable sources
Look like there are three versions of "how to subscribe to external mutable source" in React:
createSubscription
+useSubscription
useMutableSource
(was renamed to the below)useSyncExternalStore
(package)It turns out that managing
frp-ts
like source is not that easy in React because you have to take into account SSR, Suspense and async rendering (coming in React 18).My suggestion is to use
useSyncExternalStore
infrp-ts/react
package so the React team handles all the details (I'll attach reading list at the end for a better context).2 State modification during render
I know that this is an anti-pattern and it should not be done (react repo issue). But, now I wonder whether this still can happen in large codebases (sockets, event handlers, whatever).
React team introduces
StrictEffects
and this should catch the above. Until that lands, I wonder whether deferringstate.set
calls as done in most eliminates the problem completely.I still need to wrap my head around this. Maybe this case will never happen in a real application. Maybe the only way to trigger this is to directly modify the state in a render function.
Two demos showcasing this:
3 Further read
Show
Packages:
API Discussions:
react-redux migration to
useSES
:mobx issues:
New version of the
useProperty
hookI tested my component with the hook below and everything seems to work fine.
Summary
useSyncExternalStore
is the way to go forfrp-ts
React integration.frp-ts
).The text was updated successfully, but these errors were encountered: