-
In my hooks I am often combining const { session } = useSession()
const { data, error, mutate } = useSWR(session?.id ? ["/v2/order/recipe/summary", session.id] : null,
(path, sessionId) => get(path, sessionId).then(normalise)
)
const uploadPhoto = React.useCallback((path: string) => {
return post(..., session.id).then(mutate).catch(setError)
}, [session, mutate] In my hook callbacks it would be nice to be able to use the already existing and exported swr Otherwise I'd have to setup a Any patterns that could help to streamline error reporting? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can pass a rejected promise to mutate(() => Promise.reject(error)); Something like that should work. |
Beta Was this translation helpful? Give feedback.
You can pass a rejected promise to
mutate
and it will update the cache of the key with the errorSomething like that should work.