React Hook useEffect has a missing dependency: 'init'. Either include it or remove the dependency array react-hooks/exhaustive-deps
src/admin/apiAdmin.js
export const getCategories = () => {
return fetch(`${API}/categories`, {
method: 'GET'
})
.then(response => {
return response.json()
})
.catch(err => console.log(err))
}
src/AddProduct.js
//load categories and set form data
const init = () => {
getCategories().then(data => {
if (data.error) {
setValues({ ...values, error: data.error })
} else {
// console.log(data)
setValues({
...values,
categories: data.data,
formData: new FormData()
})
}
})
}
useEffect(() => {
init();
}, [])
useEffect(someFn, []);
is a perfectly fine way to run a side-effect on mount. – Jared Smith