Using connect and mapDispatchToProps with functional components

I am experimenting with Redux. I understand to dispatch action to the store from functional components, one can subscribe using useDispatch hook. I am dispatching action from useEffect and according to react-redux doc., dispatch can be omitted from list of dependencies to useEffect because its identity is stable .

  const TriviaCategories = () => {
  const dispatch = useDispatch();
  useEffect(() => {
  //fetch data from API
    dispatch({ type: "SET_CATEGORIES", triviaCategories });
  }, []);
  return null;

If i decide to use connect to subscribe to the store, will the dispatch function identity still be stable like with useDispatch hook?

I’ve never used it, but why would you bother? If you have connect, why not just use that? I would say to use one or the other. But it should work, I would think, since it’s just returning a reference.

Yes it does work for both cases. My concern was whether dispatch function’s identity is stable when you subscribe to the store via connect. I am interested in this because i am dispatching action from useEffect which requires me to pass dispatch as a dependency. If its identity is not stable that would mean my effect will be invoked on every render which is not what i want. However i have learned that dispatch will always be stable unless a different store is passed to Provider. Therefore passing it as a dependency to useEffect is fine.

Yeah, that all makes sense. I would have assumed it would be stable, but I can understand your concern.