I am using React with Typescript and redux with the thunk layer. So, I defined one of my action as follows and it deals with a firestore snapshot listener.
export const getEmployees = () : ThunkAction<void, RootState, null, TableActions> => {
const db = fire.firestore();
return async dispatch => {
db.collection("collection_name").get().then((querySnapshot) => {
// body
});
}
};
and I dispatched it as following when a component will mount.
useEffect(() => {
dispatch(getEmployees());
},[]);
So, my question is there any best way to unsubscribe the listener when a component will unmount?