Optional
Conditional fetching as option
Moving this to an option allows us to keep the endpoints typed dictionary, e.g. we can write:
const { data, mutate } = myApi.use("User/{id}", { params: { id: aVariableMaybeContainingAnId || "" }, }, { when: !!aVariableMaybeContainingAnId });// we still have typed `data`, `mutate` Copy
const { data, mutate } = myApi.use("User/{id}", { params: { id: aVariableMaybeContainingAnId || "" }, }, { when: !!aVariableMaybeContainingAnId });// we still have typed `data`, `mutate`
https://swr.vercel.app/docs/conditional-fetching
Conditional fetching as option
Moving this to an option allows us to keep the endpoints typed dictionary, e.g. we can write: