typescript version of createCrudHook?
export default function createCrudHooks({
baseKey,
indexFn,
singleFn,
createFn,
updateFn,
deleteFn,
}) {
const useIndex = (config) => useQuery([baseKey], indexFn, config)
const useSingle = (id, config) =>
useQuery([baseKey, id], () => singleFn(id), config)
const useCreate = (config = {}) =>
useMutation(createFn, {
...config,
onSuccess: (...args) => {
queryCache.invalidateQueries([baseKey])
if (config.onSuccess) config.onSuccess(...args)
},
})
const useUpdate = (config = {}) =>
useMutation(updateFn, {
...config,
onSuccess: (...args) => {
queryCache.invalidateQueries([baseKey])
if (config.onSuccess) config.onSuccess(...args)
},
})
const useDelete = (config = {}) =>
useMutation(deleteFn, {
...config,
onSuccess: (...args) => {
queryCache.invalidateQueries([baseKey])
if (config.onSuccess) config.onSuccess(...args)
},
})
return [useIndex, useSingle, useCreate, useUpdate, useDelete]
}
this code m getting from here https://gist.github.com/tannerlinsley/c6c0064239e0bcf40ca3703f95c0fb11
i need typescript version of this kindly anyone provide codeSandbox for this @TkDodo 🔮
Gist
A naive, but efficient starter to generate crud hooks for React Query
A naive, but efficient starter to generate crud hooks for React Query - createCrudHooks.js
1 Reply
absent-sapphireOP•3y ago
@Ephem