When I remove , []) dependencies it's okay, but creating an infinite loop - with it, I have this error and other elements are not working properly.
However, how can I fix it? I can't figure out why am I getting the error below:
Thanks
Line 74:8: React Hook useEffect has a missing dependency: 'database'. Either include it or remove the dependency array. You can also do a functional
update 'setDatabase(d => ...)' if you only need 'database' in the 'setDatabase' call react-hooks/exhaustive-deps
function AddOrder(props) {
const [step, setStep] = useState(1)
const [redirect, setRedirect] = useState(false)
const [database, setDatabase] = useState({
clients: [],
orders: [],
client: [],
products: [],
subProducts: [],
filteredSubProducts: [],
useEffect(() => {
axios.get('http://127.0.0.1:8000/api/clients')
.then(res => {
setDatabase({...database, clients: res.data})
})
axios.get('http://127.0.0.1:8000/api/orders')
.then(res => {
setDatabase({...database, orders: res.data})
})
axios.get('http://127.0.0.1:8000/api/products')
.then(res => {
setDatabase({...database, products: res.data})
})
axios.get('http://127.0.0.1:8000/api/subProducts')
.then(res => {
setDatabase({...database, subProducts: res.data})
})
}, []);