React UseFetch
npm install @asosunoff/react_use_fetchhttps://asosunoff.github.io/React-Use-Fetch/
npm i @asosunoff/react_use_fetch
```
git clone https://github.com/aSosunoff/React-Use-Fetch.git
cd React-Use-Fetch
npm i
npm run demo
``
npm test
`js
import { useFetchByUrl } from "@asosunoff/react_use_fetch";
interface IPost {
userId: number;
id: number;
title: string;
body: string;
}
const App: React.FC = () => {
const [{ status, data }, doFetch] = useFetchByUrl
"https://jsonplaceholder.typicode.com/posts"
);
return (
| {userId} | {id} | {title} | {body} |
|---|
export default App;
`
`js
import { useFetchByCallback } from "@asosunoff/react_use_fetch";
interface IPost {
userId: number;
id: number;
title: string;
body: string;
}
const App: React.FC = () => {
const [{ status, data }, doFetch] = useFetchByCallback
async () => {
const response = await fetch(
"https://jsonplaceholder.typicode.com/posts"
);
if (!response.ok) {
const body = await response.json();
throw body;
}
const data = await response.json();
return data;
}
);
return (
| {userId} | {id} | {title} | {body} |
|---|
export default App;
``