An open API service indexing awesome lists of open source software.

https://github.com/legitcode/react-fetch

Component wrapper for isomorphic-fetch, passes response to children
https://github.com/legitcode/react-fetch

Last synced: 6 months ago
JSON representation

Component wrapper for isomorphic-fetch, passes response to children

Awesome Lists containing this project

README

          

# React Fetch

## Install

npm install react-fetch

## Props

- `url`: where to fetch json data from
- `onSuccess`: function on successfully fetching the data
- `onError`: function to be called on error
- `options`: object containing parameters for the request (see the [fetch](https://fetch.spec.whatwg.org/) spec)

## Example

pass an api endpoint and the resulting object will be passed as a prop.

```js
import React from "react";
import Fetch from "react-fetch";

function App() {
const handleError = (error) => console.log(error);
const handleSuccess = (data) => console.log(data);

return (



);
}

function UserAgent(props) {
return (


{props.headers ? (
Your User-Agent: {props.headers["User-Agent"]}

) : (
"Loading ..."
)}

);
}
```

### Rebuilding

Run this to view the example in `example/dist`

npm install
npm run build