Pardon me if this is a silly question. Im a new react learner. Im trying using a create react app. I am using a custom hook for API handling only. Now I want the useEffect to run only when the data changes. Thats why I put it in dependency. But yet it keeps rendering for infinity. What is the problem? Or how should I handle this? Thank you.
import { useCallback, useEffect, useState } from "react";
export const useAPI = (url, options) => {
const [data, setData] = useState([]);
const getDogCollection = useCallback(() => {
fetch(url, options)
.then((res) => res.json())
.then((result) => {
console.log(data, "----DI---", result);
setData(result);
});
}, []);
useEffect(() => {
getDogCollection();
}, [data]);
return data;
};