
UI guy @iqvia Amsterdam 💪
- Tweets299
- Following232
- Followers31
- Likes163
![// useProducts.ts const keys = { getProducts: ["products"], }; export function useGetProducts(options) { return useQuery({ queryFn: async () => { const resp = await fetch("api/products"); return resp.json(); }, queryKey: keys.getProducts, }); } export function useDeleteProduct(options) { const queryClient = useQueryClient(); return useMutation({ mutationFn: async (productId) => { const resp = await fetch("api/products/" + productId, { method: "DELETE", }); return resp.json(); }, onSuccess: () => { // Invalidate query after removing record. queryClient.invalidateQueries(keys.getProducts); options.onSuccess(); }, }); }](https://pbs.twimg.com/media/F-0dhZ6WEAAYmW5.jpg?name=small&format=webp)
ALT // useProducts.ts const keys = { getProducts: ["products"], }; export function useGetProducts(options) { return useQuery({ queryFn: async () => { const resp = await fetch("api/products"); return resp.json(); }, queryKey: keys.getProducts, }); } export function useDeleteProduct(options) { const queryClient = useQueryClient(); return useMutation({ mutationFn: async (productId) => { const resp = await fetch("api/products/" + productId, { method: "DELETE", }); return resp.json(); }, onSuccess: () => { // Invalidate query after removing record. queryClient.invalidateQueries(keys.getProducts); options.onSuccess(); }, }); }



















![img { max-width: 100%; /* [1] */ height: auto; /* [1] */ vertical-align: middle; /* [2] */ font-style: italic; /* [3] */ background-repeat: no-repeat; /* [4] */ background-size: cover; /* [4] */ shape-margin: 0.75rem; /* [5] */ }](https://pbs.twimg.com/media/F9bvvn-WwAAPwS7.jpg?name=small&format=webp)









