Valid types for SWR keys.
SWR keys identify unique requests and can be:
string
ArgumentsTuple
Record<any, any>
null | undefined | false
When a key is falsy, SWR will not make the request, allowing for conditional fetching based on application state.
// String keyuseSWR('/api/users', fetcher)// Array key with parametersuseSWR(['/api/user', userId], ([url, id]) => fetcher(`${url}/${id}`))// Object keyuseSWR({ url: '/api/data', params: { page: 1 } }, fetcher)// Conditional keyuseSWR(userId ? `/api/user/${userId}` : null, fetcher) Copy
// String keyuseSWR('/api/users', fetcher)// Array key with parametersuseSWR(['/api/user', userId], ([url, id]) => fetcher(`${url}/${id}`))// Object keyuseSWR({ url: '/api/data', params: { page: 1 } }, fetcher)// Conditional keyuseSWR(userId ? `/api/user/${userId}` : null, fetcher)
Valid types for SWR keys.
SWR keys identify unique requests and can be:
string: Simple URL or identifierArgumentsTuple: Array with URL and additional parametersRecord<any, any>: Object that will be serializednull | undefined | false: Falsy values disable the requestWhen a key is falsy, SWR will not make the request, allowing for conditional fetching based on application state.