Skip to content

Conversation

@paulobmarcos
Copy link
Contributor

Following up with the implementation of Discussion #5588.

Summary:

With notifyOnChangeProps we 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 notifyOnChangeProps value and there are use cases where the extra re-render could be considered expensive (React-Native and transitions).

Proposal:
The notifyOnChangeProps would be extended to also accept a callback. This way, we could change the return value of notifyOnChangeProps without an extra re-render.

CC: @TkDodo @ferrannp

@vercel
Copy link

vercel bot commented Jul 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) Jul 21, 2023 8:26am

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 18, 2023

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:

Sandbox Source
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

@paulobmarcos paulobmarcos force-pushed the feature/notifyOnChangePros-function branch from f2c0283 to fc9c478 Compare July 18, 2023 10:45
focusedRef.current = false
}
}, [])
)
Copy link
Contributor Author

@paulobmarcos paulobmarcos Jul 18, 2023

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
Copy link

nx-cloud bot commented Jul 18, 2023

☁️ Nx Cloud Report

CI 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 targets

Sent with 💌 from NxCloud.

@paulobmarcos paulobmarcos force-pushed the feature/notifyOnChangePros-function branch from fc9c478 to c642ac7 Compare July 18, 2023 13:34

## 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.
Copy link
Contributor

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 ?

Copy link
Contributor Author

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 👍

@TkDodo TkDodo merged commit 74f2e28 into TanStack:main Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants