DefinitelyTyped/types/react-request/react-request-tests.tsx
Danny Cochran 99b18f3c66 Add typings for react-request (#27376)
* add typings for react-request

* fix react-request types

* remove reference path

* try specifying a typescript version in index.d.ts

* pin to 2.9 instead of 2.9.2

* fix linting issues

* fix index.d.ts lint issues
2018-07-25 11:44:09 -07:00

23 lines
544 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 }) => {
if (fetching || !response) {
return <p>Loading...</p>;
}
if (failed) {
return <h2>Failed to load</h2>;
}
return <p>{data ? data.foo : 'data was null'}</p>;
}}
</Fetch>;
}
}