-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat: add new function type to notifyOnChangeProps #5734
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
feat: add new function type to notifyOnChangeProps #5734
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4247512:
|
f2c0283 to
fc9c478
Compare
| focusedRef.current = false | ||
| } | ||
| }, []) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably simplify this further with navigation.isFocused(). Something we have to try out.
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 4247512. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
fc9c478 to
c642ac7
Compare
|
|
||
| ## Disable re-renders on out of focus Screens | ||
|
|
||
| In some situations, including performance concerns, you may want to stop re-renders when a React Native screen gets out of focus. To achieve this we can use `useFocusEffect` from `@react-navigation/native` together with the `notifyOnChangeProps` query option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question if you may, when the screen gets out of focus, does effects clean up get called ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @incepter!
Yes, useFocusEffect runs the cleanup whenever a screen/component gets out of focus 👍
Following up with the implementation of Discussion #5588.
Summary:
With
notifyOnChangePropswe can make a component only re-render if any of the listed properties change. This is very useful and we can completely stop all re-renders if needed with an empty array[].However, this still requires one extra re-render to change the
notifyOnChangePropsvalue and there are use cases where the extra re-render could be considered expensive (React-Native and transitions).Proposal:
The
notifyOnChangePropswould be extended to also accept a callback. This way, we could change the return value ofnotifyOnChangePropswithout an extra re-render.CC: @TkDodo @ferrannp