'When should I use dependency in useEffect in react?
import { useEffect, useState } from "react";
const useItems = () => {
const [items, setItems] = useState([]);
const [change, setChanges] = useState('hello');
useEffect(() =>{
fetch('http://localhost:5000/items')
.then(res => res.json())
.then(data => setItems(data))
}, [change])
return [items, setItems];
}
export default useItems;
In this code I can see dependency, I don't know why they used useEffect dependency.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
