mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Add missing doFetch type to react-request RenderProps
This commit is contained in:
Vendored
+1
@@ -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 {
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user