Skip to content

Latest commit

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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 spec)

Example

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

importReactfrom"react";importFetchfrom"react-fetch";functionApp(){consthandleError=(error)=>console.log(error);consthandleSuccess=(data)=>console.log(data);return(<Fetchurl="http://httpbin.org/headers"onSuccess={handleSuccess}onError={handleError}><UserAgent/></Fetch>);}functionUserAgent(props){return(<div>{props.headers ? (<div>Your User-Agent: {props.headers["User-Agent"]}</div>) : ("Loading ...")}</div>);}

Rebuilding

Run this to view the example in example/dist

npm install
npm run build

About

Component wrapper for isomorphic-fetch, passes response to children

Resources

Stars

120 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages