React Hook useEffect缺少依赖项-Mobx

问题描述 投票:0回答:1

我正在使用mobx并将钩子一起反应。我有一个useContext来获取存储功能

const store = useContext(MyStore)
useEffect(() => {
        if (init !== '') {
            store.loading = true;
            store.bulkApprove(init).then(data => {
                store.unCheckAll();
            });
        }
    }, [init]);

我可以看到类似以下的警告

 React Hook useEffect has a missing dependency: 'store'. Either include it or remove the dependency array

我真的很困惑,为什么我需要在依赖项数组中包括存储

javascript reactjs react-hooks mobx
1个回答
0
投票

[React Hook useEffect has a missing dependency: <dep>. Either include it or remove the dependency array仅仅意味着短绒棉签警告您,您的依赖项依赖于可能改变的外部值。

store已订阅上下文MyStore。表示它正在跟踪其更改。

© www.soinside.com 2019 - 2024. All rights reserved.