is it okay to use useDispatch
hook inside a function
or a class
? I am not talking about functional or class components. I want to dispatch a state change from function/class.
// Example: utils.ts
export function foo(){
const bar = getBar();
const dispatch = useDispatch();
dispatch(addBar(bar))
}
No, things that begin with use
are hooks and can only be used in function components.
If you want access to dispatch from a function, do one of
store.dispatch