Skip to content
Discussion options

You must be logged in to vote

by typing them all to unknown, you'll likely have a hard time using e.g. the context or the returned data / error with correct types.

The generics are:

  1. TData = unknown: The type of data, in your case, what Api.locations.create returns
  2. TError = unknown: The type of error that is thrown, unknown is most correct here, but you can also narrow it to AxiosError or so if you're using that.
  3. TVariables = void: The variables passed, ILocationPayload in your case.
  4. TContext = unknown: context is used for optimistic updates and is usually inferred from the return value of onMutate. Since you let the users of your custom hook specify onMutate, you can't use that without explicitly using a generic.

so…

Replies: 1 comment 1 reply

Comment options

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

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