I have a function that takes in a callback and returns the value obtained using the useSelector
hook from the react-redux
library.
Is there a way to utilize the return type of useSelector
within my wrapper function?
import { shallowEqual, useSelector } from 'react-redux';
type SelectorFunction = (state: AppState) => /* TypeOfReturn */;
export default (selector: SelectorFunction) => useSelector(selector, shallowEqual);
Currently, my function outputs any
, but I would like to avoid manual type assertions like this:
const user = useShallowEqualSelector(state => state.userAuth.user) as User | null;
If I only use useSelector
directly, the type of user
is correctly inferred as User | null
:
const user = useSelector((state: AppState) => state.userAuth.user);