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
- Host: GitHub
- URL: https://github.com/legitcode/react-fetch
- Owner: Legitcode
- Created: 2015-06-01T22:12:29.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-12-26T17:19:22.000Z (about 5 years ago)
- Last Synced: 2024-05-21T11:19:16.181Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://zach.codes/react-fetch/example/dist/
- Size: 2.14 MB
- Stars: 119
- Watchers: 10
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
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