react-requests-fetch
v0.2.5
Published
The given dependency, <b>[react-requests-fetch]</b> is a <a href="https://reactjs.org/">ReactJS</a> target library for handling http fetch requests considering bia-directional stateless and stateful data extraction. The same logic and parameters used whe
Downloads
16
Readme
React Request Fetch Hook
The given dependency, [react-requests-fetch] is a ReactJS target library for handling http fetch requests considering bia-directional stateless and stateful data extraction. The same logic and parameters used when performing http requests using the fetch api are kept, with the difference in flexibility as to how data is retrieved. Data can be retrieved from any given source (api: precisely), either by initializing this hook when the component renders or is to render with statics variables, or dynamic variables within the source code, the same way as the react's use state hook is expected to be called.
import useRequestFetch from "react-requests-fetch";
const [response, setRequest] = useRequestFetch({
uri: "https://restcountries.eu/rest/v2/all"
});
<button onClick={() => {
setRequest({
uri: "https://restcountries.eu/rest/v2/alpha/col"
})
}}>Fetch Data</button>
<p>{response.loading && "Fetching..."}</p>
<pre>{JSON.stringify(response, null, 2)}</pre>
{
"statusCode": 200,
"loading": false,
"payload": []
}