1

我正在使用带有 Typescript 的 React 和带有 thunk 层的 redux。因此,我将我的一项操作定义如下,它处理 Firestore 快照侦听器。

export const getEmployees = () : ThunkAction<void, RootState, null, TableActions> => {

    const db = fire.firestore();

    return async dispatch => {
        db.collection("collection_name").get().then((querySnapshot) => {
            // body
        });
    }
};

当组件安装时,我按以下方式发送它。

useEffect(() => {
   dispatch(getEmployees());
},[]);

所以,我的问题是当组件卸载时有什么最好的方法来取消订阅监听器?

4

0 回答 0