How to get state in React function without unnecessary rerender? #5099
Answered
by
EskiMojo14
michalvadak
asked this question in
Q&A
-
Hey, is it possible to use the following in the
|
Beta Was this translation helpful? Give feedback.
Answered by
EskiMojo14
Oct 8, 2025
Replies: 1 comment 3 replies
-
assuming you're getting the store from const handleOrientationChange = useCallback(() => {
dispatch((dispatch, getState) => {
const isAutoPlayActive = getState().autoPlay.isActive;
if (isAutoPlayActive) {
dispatch(stopAutoPlay());
}
});
}, [dispatch]); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.