Skip to content

Instantly share code, notes, and snippets.

@aliakakis
Created April 22, 2024 15:19
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.
Local 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