I can't update state with new data from Tanstack Query
devoren opened this issue · comments
Summary
Hey! Thank you for awesome library ❤️
I have a form. When I update the form, onSuccess returns the new updated data. I don't understand why my state isn't updating. I don't know why its not updating, because i have the same logic inside useEffect and it works
Link to reproduction
updateStore(
{
id: store.id,
...data
},
{
onSuccess: (data) => {
// if i set store like this, not working
setStore(data.response.ressult.store)
// if i set store like this, works
setStore({
...store,
...data,
});
Notice.Success(data.result.message);
},
}
);
Store
interface StoresState {
store: IStore | null;
setStore: (store: IStore | null) => void;
}
export const useStoresStore = create<StoresState>()(
persist(
(set) => ({
store: null,
setStore: (store) => set(() => ({ store })),
clearStore: () => set({ store: null }),
}),
{
name: "stores-zsg",
}
)
);
Check List
Please do not ask questions in issues.
- I've already opened a discussion before opening this issue, or already discussed in other media.
Please include a minimal reproduction.
- I've added a link to a typescript playground or codesandbox with a minimal reproduction.
Please check this if you're filing an issue regarding TypeScript.
- I've read the typescript guide, in particular that
create
is to be used ascreate<T>()(...)
and notcreate<T>(...)
.
Any solution mate? ran into same problem. State not updating
Any solution mate? ran into same problem. State not updating
Edit:: My mistake. data was inside another data :P got it fixed