Skip to content

Commit 723a00a

Browse files
authored
docs: fix useProxySelector to use useMemo instead of useCallback (#113)
1 parent 7727fc4 commit 723a00a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

docs/react-redux/useProxySelector.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ This creates a `useProxySelector` hook which can be used to create a typed `useS
66

77
```ts
88
import { memoize } from 'proxy-memoize';
9-
import { useCallback } from 'react';
9+
import { useMemo } from 'react';
1010
import { useSelector } from 'react-redux';
1111

1212
// import your react-redux RootState type
1313
import 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

0 commit comments

Comments
 (0)