npm install react-fetch
url: where to fetch json data fromonSuccess: function on successfully fetching the dataonError: function to be called on erroroptions: object containing parameters for the request (see the fetch spec)
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>);}Run this to view the example in example/dist
npm install
npm run build