Skip to content

how to test onError behavior? #650

Answered by sergiodxa
teobler asked this question in General
Discussion options

You must be logged in to vote

Your fetcher function should throw an error, not the hook itself, also you can access the error with

const { data, error } = useSWR(key, fetcher)

You don’t need to create a different state and use onError to update it.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@teobler
Comment options

Answer selected by teobler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants