Can I call another separate function in useEffect?
I am calling another function in useEffect but after saving the file it is automatically adding that function in array parameters of useEffect.
See the code below for proper understanding.
Before saving file:
useEffect(() => {
getData()
console.log("useEffect ran...");
}, [query]);
function getData() {
fetch(`https://jsonplaceholder.typicode.com/${query}`)
.then(response => response.json())
.then(json => setData(json));
}
after saving file:
useEffect(() => {
getData();
console.log("useEffect ran...");
}, [getData, query]);
function getData() {
fetch(`https://jsonplaceholder.typicode.com/${query}`)
.then(response => response.json())
.then(json => setData(json));
}
it is running again and again.