I wanna fetch my categories whenever my component is mounted using react hooks useEffect and not on every re-render. But i keep on getting this warning React Hook useEffect has a missing dependency:'dispatch'.
Here's my code:
const categories = useSelector(state => state.category.categories); const dispatch = useDispatch(); useEffect(() => { console.log('effecting'); const fetchCategories = async () => { console.log('fetching'); try { const response = await axios.get('/api/v1/categories'); dispatch(initCategory(response.data.data.categories)); } catch (e) { console.log(e); } } fetchCategories(); }, []);