Skip to content

Instantly share code, notes, and snippets.

@aliakakis
Last active June 3, 2024 08:44
Show Gist options
  • Save aliakakis/369a88394456583e2e1a6bf71e38af28 to your computer and use it in GitHub Desktop.
Save aliakakis/369a88394456583e2e1a6bf71e38af28 to your computer and use it in GitHub Desktop.
Global state query for React Query
/*
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