Skip to content

Commit

Permalink
Fixed potential typescript error in examples/axios-typescript (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Svish authored Feb 24, 2020
1 parent 170ad57 commit 63fdb92
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions examples/axios-typescript/libs/useRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@ export default function useRequest<Data = unknown, Error = unknown>(
const { data: response, error, isValidating, revalidate } = useSWR<
AxiosResponse<Data>,
AxiosError<Error>
>(request && JSON.stringify(request), () => axios(request || {}), {
...config,
initialData: initialData && {
status: 200,
statusText: 'InitialData',
config: request,
headers: {},
data: initialData
>(
request && JSON.stringify(request),
/**
* NOTE: Typescript thinks `request` can be `null` here, but the fetcher
* function is actually only called by `useSWR` when it isn't.
*/
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
() => axios(request!),
{
...config,
initialData: initialData && {
status: 200,
statusText: 'InitialData',
config: request,
headers: {},
data: initialData
}
}
})
)

return {
data: response && response.data,
Expand Down

0 comments on commit 63fdb92

Please sign in to comment.