Last active
June 3, 2024 08:44
-
-
Save aliakakis/369a88394456583e2e1a6bf71e38af28 to your computer and use it in GitHub Desktop.
Global state query for React Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
const [storeData, setStoreData] = useStoreQuery(); | |
setStoreData((prev) => ({ ...prev, user: 'jane', country: 'US' })); | |
*/ | |
const useStoreQuery = () => { | |
const queryKey = ["storeQuery"]; | |
const initialData: InitialStoreData = { | |
bookDetails: {}, | |
}; | |
return [ | |
useQuery({ | |
queryKey, | |
queryFn: () => initialData, | |
initialData, | |
enabled: false, | |
}).data, | |
(value) => queryClient.setQueryData(queryKey, value), | |
]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment