Search code examples
javascriptreactjsreact-hooksdeveloper-tools

Error: React Hook useEffect has a missing dependency: 'setAPIData'. Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps


Facing issue that "React Hook useEffect has a missing dependency: 'setAPIData'. Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps", tried so many possible ways but still facing the same issue.

function Read() {

const { APIdata, setAPIData } = useState([]);

useEffect(() => {
    const getApiData = async () => {
        const res = await axios.get(API);
        setAPIData(res.data);
    }
    getApiData();
}, []);

console error Screenshot: enter image description here


Solution

  • This doesn't actually answer your question, but it will answer the question that you'll have next:

    const { APIdata, setAPIData } = useState([]);
    

    is wrong, it should be:

    const [ APIdata, setAPIData ] = useState([]);