relay-tools / relay-hooks

Use Relay as React hooks
https://relay-tools.github.io/relay-hooks/docs/relay-hooks.html
MIT License
540 stars 56 forks source link

poc: transient fragment for by-passing re-renders #169

Closed n1ru4l closed 2 years ago

n1ru4l commented 3 years ago

I have the need for subscribing to a fragment in a performant way in order to sync it with some not directly react related store. Doing that with useFragment and React.useEffect is not performant enough as the value updates quite frequently. For this use-case it would be beneficial to bypass re-renders and directly invoke some callback with the latest fragment data.

The naming is debatable. It seems that in the react-three-fiber community by-passing render state is usually described as transient updates. I am happy to choose any other naming though. E.g. useFragmentSubscription, useSubscriptionFragment.

I originally posted the idea in the GraphQL Slack: https://graphql.slack.com/archives/C0BEXJLKG/p1618139127305000

@morrys Please let me know how you think about this addition 😇

morrys commented 3 years ago

@n1ru4l I find this PR interesting 👍

In practice, a management of observable fragments in which the user manages how and when to render the data.

n1ru4l commented 3 years ago

@n1ru4l I find this PR interesting 👍

In practice, a management of observable fragments in which the user manages how and when to render the data.

Yes, basically how subscriptions are treated!

morrys commented 3 years ago

Due to the way relay-hooks is structured, it should also be integrated into the other hooks

morrys commented 3 years ago

next week I'll look deeper ;)

In the meantime, it would be nice to have other opinions as well (@sibelius )

sibelius commented 3 years ago

I think it is good, we just need a better name

morrys commented 3 years ago

I'd like to hear if such a PR would be interesting in react-relay as well @jstejada, @rbalicki2

morrys commented 2 years ago

https://github.com/relay-tools/relay-hooks/pull/170