EM
Size: a a a
EM
ps
EM
EM
ps
EM
EM
const useFetch = (url, options) => {
console.log('useFetch called');
const [response, setResponse] = useState(null);
const doFetch = async () => {
const res = await fetch(url, options);
const json = await res.json();
setResponse(json);
};
return { response, doFetch };
};
export default useFetch;
function A({ url, options }) {
const { response, doFetch } = useFetch(url, options);
return (
<>
<button onClick={doFetch}>do fetch</button>
{response && <div>{JSON.stringify(response)}</div>}
</>
);
}
EM
ps
ps
EM
EM
ps
ps
ps
Д
ВА
▲R