【发布时间】:2020-04-08 13:51:41
【问题描述】:
每当我的组件使用 react hooks useEffect 挂载时,我想获取我的类别,而不是在每次重新渲染时。但我不断收到此警告React Hook useEffect has a missing dependency:'dispatch'。
这是我的代码:
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();
}, []);
【问题讨论】:
标签: reactjs redux react-redux react-hooks