diff --git a/types/react-request/index.d.ts b/types/react-request/index.d.ts index 0806dda260..3134825fbe 100644 --- a/types/react-request/index.d.ts +++ b/types/react-request/index.d.ts @@ -15,6 +15,7 @@ export interface RenderProps { response: Response | null; url: string; data: T | null; + doFetch: (options?: FetchRequestProps) => Promise; } export interface FetchRequestProps extends RequestInit { diff --git a/types/react-request/react-request-tests.tsx b/types/react-request/react-request-tests.tsx index 6a4ff71212..5e5edf31d2 100644 --- a/types/react-request/react-request-tests.tsx +++ b/types/react-request/react-request-tests.tsx @@ -8,13 +8,16 @@ interface ServerResponse { export default class BasicReactRequest extends React.Component { render() { return url='/api/server'> - {({ fetching, failed, data, response }) => { + {({ fetching, failed, data, response, doFetch }) => { if (fetching || !response) { return

Loading...

; } if (failed) { return

Failed to load

; } + if (!data) { + doFetch(); + } return

{data ? data.foo : 'data was null'}

; }} ;