Skip to content

Commit 0f65c2a

Browse files
committed
Add JSDocs for useSelector
1 parent e747c63 commit 0f65c2a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/hooks/useSelector.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,53 @@ export interface UseSelectorOptions<Selected = unknown> {
6666
devModeChecks?: Partial<DevModeChecks>
6767
}
6868

69+
/**
70+
* Represents a custom hook that allows you to extract data from the
71+
* Redux store state, using a selector function. The selector function
72+
* takes the current state as an argument and returns a part of the state
73+
* or some derived data. The hook also supports an optional equality
74+
* function or options object to customize its behavior.
75+
*
76+
* @template StateType - The specific type of state this hook operates on.
77+
*
78+
* @public
79+
*/
6980
export interface UseSelector<StateType = unknown> {
81+
/**
82+
* A function that takes a selector function as its first argument.
83+
* The selector function is responsible for selecting a part of
84+
* the Redux store's state or computing derived data.
85+
*
86+
* @param selector - A function that receives the current state and returns a part of the state or some derived data.
87+
* @param equalityFnOrOptions - An optional equality function or options object for customizing the behavior of the selector.
88+
* @returns The selected part of the state or derived data.
89+
*
90+
* @template TState - The specific type of state this hook operates on.
91+
* @template Selected - The type of the value that the selector function will return.
92+
*/
7093
<TState extends StateType = StateType, Selected = unknown>(
7194
selector: (state: TState) => Selected,
7295
equalityFnOrOptions?: EqualityFn<Selected> | UseSelectorOptions<Selected>
7396
): Selected
7497

98+
/**
99+
* Creates a "pre-typed" version of {@linkcode useSelector useSelector}
100+
* where the `state` type is predefined.
101+
*
102+
* This allows you to set the `state` type once, eliminating the need to
103+
* specify it with every {@linkcode useSelector useSelector} call.
104+
*
105+
* @returns A pre-typed `useSelector` with the state type already defined.
106+
*
107+
* @example
108+
* ```ts
109+
* const useAppSelector = useSelector.withTypes<RootState>()
110+
* ```
111+
*
112+
* @template OverrideStateType - The specific type of state this hook operates on.
113+
*
114+
* @since 9.1.0
115+
*/
75116
withTypes: <
76117
OverrideStateType extends StateType
77118
>() => UseSelector<OverrideStateType>

0 commit comments

Comments
 (0)