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
-
Since v3, we now have
notifyOnChangeProps
so that we can optimize our renders by only "subscribing" to certain changes, e.g.:This component will only re-render if the
data
changes, 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: true
and 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
get
interceptor, which would then just fill ournotifyOnChangeProps
might 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
data
changes because that's what we access, and if we further accessstatus
orerror
, we would also subscribe to these changes. I think this would be a nice optimization because most components don't need the latestupdatedAt
timestamp orisFetching
property, which is what's mostly causing re-renders during background refetches.What do you think?
Beta Was this translation helpful? Give feedback.
All reactions