mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
26 lines
607 B
TypeScript
26 lines
607 B
TypeScript
import * as React from "react";
|
|
import { Fetch } from "react-request";
|
|
|
|
interface ServerResponse {
|
|
foo: string;
|
|
}
|
|
|
|
export default class BasicReactRequest extends React.Component {
|
|
render() {
|
|
return <Fetch<ServerResponse> url='/api/server'>
|
|
{({ 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>;
|
|
}
|
|
}
|