This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C-1091] Improve selector performance (#1932)
- Loading branch information
1 parent
eee12c7
commit 43222ee
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { DependencyList } from 'react' | ||
import { useCallback } from 'react' | ||
|
||
import type { CommonState } from '@audius/common' | ||
import memoize from 'proxy-memoize' | ||
import { useSelector } from 'react-redux' | ||
|
||
const createProxySelectorHook = <TState extends object = any>() => { | ||
const useProxySelector = <TReturnType>( | ||
fn: (state: TState) => TReturnType, | ||
deps: DependencyList | ||
): TReturnType => { | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
return useSelector(useCallback(memoize(fn), deps)) | ||
} | ||
return useProxySelector | ||
} | ||
|
||
export const useProxySelector = createProxySelectorHook<CommonState>() |