File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,20 +6,24 @@ This creates a `useProxySelector` hook which can be used to create a typed `useS
66
77``` ts
88import { memoize } from ' proxy-memoize' ;
9- import { useCallback } from ' react' ;
9+ import { useMemo } from ' react' ;
1010import { useSelector } from ' react-redux' ;
1111
1212// import your react-redux RootState type
1313import type { RootState } from ' ./path/to/root/state/declaration' ;
1414
15- const createProxySelectorHook = <TState extends object = any >() => {
15+ const createProxySelectorHook = <TState extends object >() => {
16+ const useTypedSelector = useSelector .withTypes <TState >();
17+
1618 const useProxySelector = <TReturnType >(
1719 fn : (state : TState ) => TReturnType ,
18- deps ? : any [],
20+ deps : React . DependencyList = [],
1921 ): TReturnType => {
2022 // eslint-disable-next-line react-hooks/exhaustive-deps
21- return useSelector (useCallback (memoize (fn ), deps ));
23+ const selector = useMemo (() => memoize (fn ), deps );
24+ return useTypedSelector (selector );
2225 };
26+
2327 return useProxySelector ;
2428};
2529
You can’t perform that action at this time.
0 commit comments