Skip to content
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

React-query v5 OnSuccess, OnError ... #51

Open
lveillard opened this issue Oct 19, 2023 · 1 comment
Open

React-query v5 OnSuccess, OnError ... #51

lveillard opened this issue Oct 19, 2023 · 1 comment

Comments

@lveillard
Copy link

Hello!

When updating to tanstack query v5 there is a relevant breaking change to consider:
https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose

=> onSuccess and the other callbacks will not be available.

In our case, we are currently using the onSuccess of a atomWithQuery to set another atom, something like this:

 const loadAndCacheUnitAtom = atom(null, async (get, set, { unitId, onSuccess }) => {
	
       const [loadUnitAtomTwo] = atomsWithQuery((g) => {

		return {
			queryKey: ['units', unitId],
			queryFn: async () => query(spaceId, payload),
			onSuccess: (data: any) => {
				if (onSuccess) {
					const { units } = data;
					set(setUnitsMapAtom, units);
				}
			},
		};
	});
	return get(loadUnitAtomTwo);
});

the ugly alternative for this in react query when you really need to sync your store is to use useEffect:
image

How can we get the same result here and properly do a set to another atom on query sucess?

Thanks!

@lveillard lveillard changed the title React-query v5 React-query v5 OnSuccess, OnError ... Oct 19, 2023
@dai-shi
Copy link
Member

dai-shi commented Oct 19, 2023

Related: #42
WIP: #45

You are welcome to join this effort.

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

No branches or pull requests

2 participants