Hooks can only be called inside of the body

I created a custom hook usePostCategory to post a new category. The hook is called from another component, but when I try to do it, I receive an error: " Invalid hook call. Hooks can only be called inside of the body of a function component". Just wondering if I call the hook in the… Read More Hooks can only be called inside of the body

isLoading not working when changing state in custom hook

I am using a custom useFetch function, the isLoading function is working if the window reloads but when i change the state with useState hooks, the custom hooks works but isLoading is not working. – const [url, setUrl] = useState(‘/api’) const [name, setName] = useState(“random”); const filterChoice = (e) => { const value = document.getElementById(‘filter’).value;… Read More isLoading not working when changing state in custom hook

Why or when should I use state within a custom Hook in React?

I am learning about custom Hooks in React. I have taken the following typical example (useFetch) as you can see in https://www.w3schools.com/react/react_customhooks.asp. import { useState, useEffect } from "react"; const useFetch = (url) => { const [data, setData] = useState(null); /* <— Why use this? */ useEffect(() => { fetch(url).then((res) => res.json()).then((data) => setData(data)); },… Read More Why or when should I use state within a custom Hook in React?