Skip to content
Discussion options

You must be logged in to vote

If you're using Typescript you should be using pre-typed hooks, which would give it the correct store type.

The thunk is slightly simpler, so I'd stick with it where possible.

It also means you can extract it outside the component, removing the need for the useCallback altogether.

const stopAutoPlayThunk = (): AppThunk => (dispatch, getState) => {
  const isAutoPlayActive = getState().autoPlay.isActive;

  if (isAutoPlayActive) {
    dispatch(stopAutoPlay());
  }
}

function Component() {
  const dispatch = useAppDispatch();
  // then just dispatch(stopAutoPlayThunk())
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@michalvadak
Comment options

@EskiMojo14
Comment options

Answer selected by michalvadak
@michalvadak
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants