This is my custom hook:
function useFetch({url = '', method = 'get', body}) {
const [data, setData] = useState(null);
useEffect(() => {
try {
(async () => {
const data = await fetch[method](url, body);
setData(data);
})();
} catch (err) {
console.log("An error ocurred")
}
}, [url, method, body]);
return [(!data && <LoadingIcon />, data, setData];
}
I want to execute setUserFeedbackMsg("An error ocurred"), which is part of a context component, every time an error ocurrs on any instantiation of the hook. Of course I could do it manually on every component that uses the hook, but I'm wondering if there's a way to condense it all in one place. Thank you!