Add missing doFetch type to react-request RenderProps

This commit is contained in:
JGeppert
2019-02-25 09:22:04 +01:00
parent b1285dace3
commit fa8122b070
2 changed files with 5 additions and 1 deletions
+1
View File
@@ -15,6 +15,7 @@ export interface RenderProps<T> {
response: Response | null;
url: string;
data: T | null;
doFetch: (options?: FetchRequestProps) => Promise<void>;
}
export interface FetchRequestProps extends RequestInit {
+4 -1
View File
@@ -8,13 +8,16 @@ interface ServerResponse {
export default class BasicReactRequest extends React.Component {
render() {
return <Fetch<ServerResponse> url='/api/server'>
{({ fetching, failed, data, response }) => {
{({ fetching, failed, data, response, doFetch }) => {
if (fetching || !response) {
return <p>Loading...</p>;
}
if (failed) {
return <h2>Failed to load</h2>;
}
if (!data) {
doFetch();
}
return <p>{data ? data.foo : 'data was null'}</p>;
}}
</Fetch>;