Replies: 1 comment 5 replies
-
|
This would be awesome. I wonder if @dai-shi would be willing to help us out. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Since v3, we now have
notifyOnChangePropsso that we can optimize our renders by only "subscribing" to certain changes, e.g.:This component will only re-render if the
datachanges, and because of the structural sharing feature, this will only happen if we really get new data from the server.This is nice and comes in very handy if your render is expensive, because every background refetch will lead to 2 re-renders per default (switching to
isFetching: trueand then again toisFetching: false).It is however a quite manual approach to specifying what you want to subscribe to, and you have to keep it in-sync with what you are really using - it would be really cool if this could be tracked automatically!
Proxies offer such a way, for example, react-tracked works that way.
I have no experience with proxies, but I imagine keeping track of what was accessed via a
getinterceptor, which would then just fill ournotifyOnChangePropsmight be reasonable to implement. If we don't want to force proxies on users, it could be a separate hook, and the above example could become:it would only re-render if
datachanges because that's what we access, and if we further accessstatusorerror, we would also subscribe to these changes. I think this would be a nice optimization because most components don't need the latestupdatedAttimestamp orisFetchingproperty, which is what's mostly causing re-renders during background refetches.What do you think?
Beta Was this translation helpful? Give feedback.
All reactions