UNPKG

27.7 kBTypeScriptView Raw
1// Type definitions for react-redux 7.1
2// Project: https://github.com/reduxjs/react-redux
3// Definitions by: Qubo <https://github.com/tkqubo>,
4// Kenzie Togami <https://github.com/kenzierocks>,
5// Curits Layne <https://github.com/clayne11>
6// Frank Tan <https://github.com/tansongyang>
7// Nicholas Boll <https://github.com/nicholasboll>
8// Dibyo Majumdar <https://github.com/mdibyo>
9// Thomas Charlat <https://github.com/kallikrein>
10// Valentin Descamps <https://github.com/val1984>
11// Johann Rakotoharisoa <https://github.com/jrakotoharisoa>
12// Anatoli Papirovski <https://github.com/apapirovski>
13// Boris Sergeyev <https://github.com/surgeboris>
14// Søren Bruus Frank <https://github.com/soerenbf>
15// Jonathan Ziller <https://github.com/mrwolfz>
16// Dylan Vann <https://github.com/dylanvann>
17// Yuki Ito <https://github.com/Lazyuki>
18// Kazuma Ebina <https://github.com/kazuma1989>
19// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
20// TypeScript Version: 3.0
21
22import {
23 ClassAttributes,
24 Component,
25 ComponentClass,
26 ComponentType,
27 StatelessComponent,
28 Context,
29 NamedExoticComponent
30} from 'react';
31
32import {
33 Action,
34 ActionCreator,
35 AnyAction,
36 Dispatch,
37 Store
38} from 'redux';
39
40import hoistNonReactStatics = require('hoist-non-react-statics');
41
42/**
43 * This interface can be augmented by users to add default types for the root state when
44 * using `react-redux`.
45 * Use module augmentation to append your own type definition in a your_custom_type.d.ts file.
46 * https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
47 */
48// tslint:disable-next-line:no-empty-interface
49export interface DefaultRootState {}
50
51export type AnyIfEmpty<T extends object> = keyof T extends never ? any : T;
52export type RootStateOrAny = AnyIfEmpty<DefaultRootState>;
53
54// Omit taken from https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
55export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
56
57export interface DispatchProp<A extends Action = AnyAction> {
58 dispatch: Dispatch<A>;
59}
60
61export type AdvancedComponentDecorator<TProps, TOwnProps> =
62 (component: ComponentType<TProps>) => NamedExoticComponent<TOwnProps>;
63
64/**
65 * A property P will be present if:
66 * - it is present in DecorationTargetProps
67 *
68 * Its value will be dependent on the following conditions
69 * - if property P is present in InjectedProps and its definition extends the definition
70 * in DecorationTargetProps, then its definition will be that of DecorationTargetProps[P]
71 * - if property P is not present in InjectedProps then its definition will be that of
72 * DecorationTargetProps[P]
73 * - if property P is present in InjectedProps but does not extend the
74 * DecorationTargetProps[P] definition, its definition will be that of InjectedProps[P]
75 */
76export type Matching<InjectedProps, DecorationTargetProps> = {
77 [P in keyof DecorationTargetProps]: P extends keyof InjectedProps
78 ? InjectedProps[P] extends DecorationTargetProps[P]
79 ? DecorationTargetProps[P]
80 : InjectedProps[P]
81 : DecorationTargetProps[P];
82};
83
84/**
85 * a property P will be present if :
86 * - it is present in both DecorationTargetProps and InjectedProps
87 * - InjectedProps[P] can satisfy DecorationTargetProps[P]
88 * ie: decorated component can accept more types than decorator is injecting
89 *
90 * For decoration, inject props or ownProps are all optionally
91 * required by the decorated (right hand side) component.
92 * But any property required by the decorated component must be satisfied by the injected property.
93 */
94export type Shared<
95 InjectedProps,
96 DecorationTargetProps
97 > = {
98 [P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]?: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
99 };
100
101// Infers prop type from component C
102export type GetProps<C> = C extends ComponentType<infer P>
103 ? C extends ComponentClass<P> ? ClassAttributes<InstanceType<C>> & P : P
104 : never;
105
106// Applies LibraryManagedAttributes (proper handling of defaultProps
107// and propTypes), as well as defines WrappedComponent.
108export type ConnectedComponent<
109 C extends ComponentType<any>,
110 P
111> = NamedExoticComponent<JSX.LibraryManagedAttributes<C, P>> & hoistNonReactStatics.NonReactStatics<C> & {
112 WrappedComponent: C;
113};
114
115// Injects props and removes them from the prop requirements.
116// Will not pass through the injected props if they are passed in during
117// render. Also adds new prop requirements from TNeedsProps.
118export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> =
119 <C extends ComponentType<Matching<TInjectedProps, GetProps<C>>>>(
120 component: C
121 ) => ConnectedComponent<C, Omit<GetProps<C>, keyof Shared<TInjectedProps, GetProps<C>>> & TNeedsProps>;
122
123// Injects props and removes them from the prop requirements.
124// Will not pass through the injected props if they are passed in during
125// render.
126export type InferableComponentEnhancer<TInjectedProps> =
127 InferableComponentEnhancerWithProps<TInjectedProps, {}>;
128
129export type InferThunkActionCreatorType<TActionCreator extends (...args: any[]) => any> =
130 TActionCreator extends (...args: infer TParams) => (...args: any[]) => infer TReturn
131 ? (...args: TParams) => TReturn
132 : TActionCreator;
133
134export type HandleThunkActionCreator<TActionCreator> =
135 TActionCreator extends (...args: any[]) => any
136 ? InferThunkActionCreatorType<TActionCreator>
137 : TActionCreator;
138
139// redux-thunk middleware returns thunk's return value from dispatch call
140// https://github.com/reduxjs/redux-thunk#composition
141export type ResolveThunks<TDispatchProps> =
142 TDispatchProps extends { [key: string]: any }
143 ? {
144 [C in keyof TDispatchProps]: HandleThunkActionCreator<TDispatchProps[C]>
145 }
146 : TDispatchProps;
147
148// the conditional type is to support TypeScript 3.0, which does not support mapping over tuples and arrays;
149// once the typings are updated to at least TypeScript 3.1, a simple mapped type can replace this mess
150export type ResolveArrayThunks<TDispatchProps extends ReadonlyArray<any>> =
151 TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7, infer A8, infer A9]
152 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>,
153 HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>, HandleThunkActionCreator<A7>, HandleThunkActionCreator<A8>, HandleThunkActionCreator<A9>]
154 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7, infer A8]
155 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>,
156 HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>, HandleThunkActionCreator<A7>, HandleThunkActionCreator<A8>]
157 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7]
158 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>,
159 HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>, HandleThunkActionCreator<A7>]
160 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6]
161 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>, HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>]
162 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5]
163 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>, HandleThunkActionCreator<A5>]
164 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4] ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>]
165 : TDispatchProps extends [infer A1, infer A2, infer A3] ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>]
166 : TDispatchProps extends [infer A1, infer A2] ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>]
167 : TDispatchProps extends [infer A1] ? [HandleThunkActionCreator<A1>]
168 : TDispatchProps extends Array<infer A> ? Array<HandleThunkActionCreator<A>>
169 : TDispatchProps extends ReadonlyArray<infer A> ? ReadonlyArray<HandleThunkActionCreator<A>>
170 : never
171 ;
172
173/**
174 * Connects a React component to a Redux store.
175 *
176 * - Without arguments, just wraps the component, without changing the behavior / props
177 *
178 * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior
179 * is to override ownProps (as stated in the docs), so what remains is everything that's
180 * not a state or dispatch prop
181 *
182 * - When 3rd param is passed, we don't know if ownProps propagate and whether they
183 * should be valid component props, because it depends on mergeProps implementation.
184 * As such, it is the user's responsibility to extend ownProps interface from state or
185 * dispatch props or both when applicable
186 *
187 * @param mapStateToProps
188 * @param mapDispatchToProps
189 * @param mergeProps
190 * @param options
191 */
192export interface Connect {
193 // tslint:disable:no-unnecessary-generics
194 (): InferableComponentEnhancer<DispatchProp>;
195
196 <TStateProps = {}, no_dispatch = {}, TOwnProps = {}, State = DefaultRootState>(
197 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>
198 ): InferableComponentEnhancerWithProps<TStateProps & DispatchProp, TOwnProps>;
199
200 <no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
201 mapStateToProps: null | undefined,
202 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>
203 ): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
204
205 <no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
206 mapStateToProps: null | undefined,
207 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
208 ): InferableComponentEnhancerWithProps<
209 ResolveThunks<TDispatchProps>,
210 TOwnProps
211 >;
212
213 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultRootState>(
214 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
215 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>
216 ): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>;
217
218 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultRootState>(
219 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
220 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
221 ): InferableComponentEnhancerWithProps<
222 TStateProps & ResolveThunks<TDispatchProps>,
223 TOwnProps
224 >;
225
226 <no_state = {}, no_dispatch = {}, TOwnProps = {}, TMergedProps = {}>(
227 mapStateToProps: null | undefined,
228 mapDispatchToProps: null | undefined,
229 mergeProps: MergeProps<undefined, undefined, TOwnProps, TMergedProps>,
230 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
231
232 <TStateProps = {}, no_dispatch = {}, TOwnProps = {}, TMergedProps = {}, State = DefaultRootState>(
233 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
234 mapDispatchToProps: null | undefined,
235 mergeProps: MergeProps<TStateProps, undefined, TOwnProps, TMergedProps>,
236 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
237
238 <no_state = {}, TDispatchProps = {}, TOwnProps = {}, TMergedProps = {}>(
239 mapStateToProps: null | undefined,
240 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
241 mergeProps: MergeProps<undefined, TDispatchProps, TOwnProps, TMergedProps>,
242 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
243
244 <TStateProps = {}, no_dispatch = {}, TOwnProps = {}, State = DefaultRootState>(
245 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
246 mapDispatchToProps: null | undefined,
247 mergeProps: null | undefined,
248 options: Options<State, TStateProps, TOwnProps>
249 ): InferableComponentEnhancerWithProps<DispatchProp & TStateProps, TOwnProps>;
250
251 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
252 mapStateToProps: null | undefined,
253 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>,
254 mergeProps: null | undefined,
255 options: Options<{}, TStateProps, TOwnProps>
256 ): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
257
258 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
259 mapStateToProps: null | undefined,
260 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
261 mergeProps: null | undefined,
262 options: Options<{}, TStateProps, TOwnProps>
263 ): InferableComponentEnhancerWithProps<
264 ResolveThunks<TDispatchProps>,
265 TOwnProps
266 >;
267
268 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultRootState>(
269 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
270 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>,
271 mergeProps: null | undefined,
272 options: Options<State, TStateProps, TOwnProps>
273 ): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>;
274
275 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultRootState>(
276 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
277 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
278 mergeProps: null | undefined,
279 options: Options<State, TStateProps, TOwnProps>
280 ): InferableComponentEnhancerWithProps<
281 TStateProps & ResolveThunks<TDispatchProps>,
282 TOwnProps
283 >;
284
285 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, TMergedProps = {}, State = DefaultRootState>(
286 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
287 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
288 mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
289 options?: Options<State, TStateProps, TOwnProps, TMergedProps>
290 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
291 // tslint:enable:no-unnecessary-generics
292}
293
294/**
295 * Infers the type of props that a connector will inject into a component.
296 */
297export type ConnectedProps<TConnector> =
298 TConnector extends InferableComponentEnhancerWithProps<infer TInjectedProps, any>
299 ? TInjectedProps
300 : never;
301
302/**
303 * The connect function. See {@type Connect} for details.
304 */
305export const connect: Connect;
306
307export type MapStateToProps<TStateProps, TOwnProps, State = DefaultRootState> =
308 (state: State, ownProps: TOwnProps) => TStateProps;
309
310export type MapStateToPropsFactory<TStateProps, TOwnProps, State = DefaultRootState> =
311 (initialState: State, ownProps: TOwnProps) => MapStateToProps<TStateProps, TOwnProps, State>;
312
313export type MapStateToPropsParam<TStateProps, TOwnProps, State = DefaultRootState> =
314 MapStateToPropsFactory<TStateProps, TOwnProps, State> | MapStateToProps<TStateProps, TOwnProps, State> | null | undefined;
315
316export type MapDispatchToPropsFunction<TDispatchProps, TOwnProps> =
317 (dispatch: Dispatch<Action>, ownProps: TOwnProps) => TDispatchProps;
318
319export type MapDispatchToProps<TDispatchProps, TOwnProps> =
320 MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | TDispatchProps;
321
322export type MapDispatchToPropsFactory<TDispatchProps, TOwnProps> =
323 (dispatch: Dispatch<Action>, ownProps: TOwnProps) => MapDispatchToPropsFunction<TDispatchProps, TOwnProps>;
324
325export type MapDispatchToPropsParam<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToProps<TDispatchProps, TOwnProps>;
326
327export type MapDispatchToPropsNonObject<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToPropsFunction<TDispatchProps, TOwnProps>;
328
329export type MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> =
330 (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps) => TMergedProps;
331
332export interface Options<State = DefaultRootState, TStateProps = {}, TOwnProps = {}, TMergedProps = {}> extends ConnectOptions {
333 /**
334 * If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps,
335 * preventing unnecessary updates, assuming that the component is a “pure” component
336 * and does not rely on any input or state other than its props and the selected Redux store’s state.
337 * Defaults to true.
338 * @default true
339 */
340 pure?: boolean;
341
342 /**
343 * When pure, compares incoming store state to its previous value.
344 * @default strictEqual
345 */
346 areStatesEqual?: (nextState: State, prevState: State) => boolean;
347
348 /**
349 * When pure, compares incoming props to its previous value.
350 * @default shallowEqual
351 */
352 areOwnPropsEqual?: (nextOwnProps: TOwnProps, prevOwnProps: TOwnProps) => boolean;
353
354 /**
355 * When pure, compares the result of mapStateToProps to its previous value.
356 * @default shallowEqual
357 */
358 areStatePropsEqual?: (nextStateProps: TStateProps, prevStateProps: TStateProps) => boolean;
359
360 /**
361 * When pure, compares the result of mergeProps to its previous value.
362 * @default shallowEqual
363 */
364 areMergedPropsEqual?: (nextMergedProps: TMergedProps, prevMergedProps: TMergedProps) => boolean;
365
366 /**
367 * If true, use React's forwardRef to expose a ref of the wrapped component
368 *
369 * @default false
370 */
371 forwardRef?: boolean;
372}
373
374/**
375 * Connects a React component to a Redux store. It is the base for {@link connect} but is less opinionated about
376 * how to combine <code>state</code>, <code>props</code>, and <code>dispatch</code> into your final props. It makes no
377 * assumptions about defaults or memoization of results, leaving those responsibilities to the caller.It does not
378 * modify the component class passed to it; instead, it returns a new, connected component for you to use.
379 *
380 * @param selectorFactory The selector factory. See SelectorFactory type for details.
381 * @param connectOptions If specified, further customizes the behavior of the connector. Additionally, any extra
382 * options will be passed through to your <code>selectorFactory</code> in the <code>factoryOptions</code> argument.
383 */
384export function connectAdvanced<S, TProps, TOwnProps, TFactoryOptions = {}>(
385 // tslint:disable-next-line no-unnecessary-generics
386 selectorFactory: SelectorFactory<S, TProps, TOwnProps, TFactoryOptions>,
387 connectOptions?: ConnectOptions & TFactoryOptions
388): AdvancedComponentDecorator<TProps, TOwnProps>;
389
390/**
391 * Initializes a selector function (during each instance's constructor). That selector function is called any time the
392 * connector component needs to compute new props, as a result of a store state change or receiving new props. The
393 * result of <code>selector</code> is expected to be a plain object, which is passed as the props to the wrapped
394 * component. If a consecutive call to <code>selector</code> returns the same object (<code>===</code>) as its previous
395 * call, the component will not be re-rendered. It's the responsibility of <code>selector</code> to return that
396 * previous object when appropriate.
397 */
398export type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> =
399 (dispatch: Dispatch<Action>, factoryOptions: TFactoryOptions) => Selector<S, TProps, TOwnProps>;
400
401export type Selector<S, TProps, TOwnProps = null> = TOwnProps extends null | undefined
402 ? (state: S) => TProps
403 : (state: S, ownProps: TOwnProps) => TProps;
404
405export interface ConnectOptions {
406 /**
407 * Computes the connector component's displayName property relative to that of the wrapped component. Usually
408 * overridden by wrapper functions.
409 *
410 * @default name => 'ConnectAdvanced('+name+')'
411 * @param componentName
412 */
413 getDisplayName?: (componentName: string) => string;
414 /**
415 * Shown in error messages. Usually overridden by wrapper functions.
416 *
417 * @default 'connectAdvanced'
418 */
419 methodName?: string;
420 /**
421 * If defined, a property named this value will be added to the props passed to the wrapped component. Its value
422 * will be the number of times the component has been rendered, which can be useful for tracking down unnecessary
423 * re-renders.
424 *
425 * @default undefined
426 */
427 renderCountProp?: string;
428 /**
429 * Controls whether the connector component subscribes to redux store state changes. If set to false, it will only
430 * re-render on <code>componentWillReceiveProps</code>.
431 *
432 * @default true
433 */
434 shouldHandleStateChanges?: boolean;
435 /**
436 * The key of props/context to get the store. You probably only need this if you are in the inadvisable position of
437 * having multiple stores.
438 *
439 * @default 'store'
440 */
441 storeKey?: string;
442 /**
443 * @deprecated Use forwardRef
444 *
445 * @default false
446 */
447 withRef?: boolean;
448 /**
449 * The react context to get the store from.
450 *
451 * @default ReactReduxContext
452 */
453 context?: Context<ReactReduxContextValue>;
454}
455
456export interface ReactReduxContextValue<SS = any, A extends Action = AnyAction> {
457 store: Store<SS, A>;
458 storeState: SS;
459}
460
461export interface ProviderProps<A extends Action = AnyAction> {
462 /**
463 * The single Redux store in your application.
464 */
465 store: Store<any, A>;
466 /**
467 * Optional context to be used internally in react-redux. Use React.createContext() to create a context to be used.
468 * If this is used, generate own connect HOC by using connectAdvanced, supplying the same context provided to the
469 * Provider. Initial value doesn't matter, as it is overwritten with the internal state of Provider.
470 */
471 context?: Context<ReactReduxContextValue>;
472}
473
474/**
475 * Makes the Redux store available to the connect() calls in the component hierarchy below.
476 */
477export class Provider<A extends Action = AnyAction> extends Component<ProviderProps<A>> { }
478
479/**
480 * Exposes the internal context used in react-redux. It is generally advised to use the connect HOC to connect to the
481 * redux store instead of this approeach.
482 */
483export const ReactReduxContext: Context<ReactReduxContextValue>;
484
485/**
486 * Wraps ReactDOM or React Native's internal unstable_batchedUpdate function. You can use it to ensure that
487 * multiple actions dispatched outside of React only result in a single render update.
488 */
489export function batch(cb: () => void): void;
490
491// tslint:disable:no-unnecessary-generics
492
493/**
494 * Compares two arbitrary values for shallow equality. Object values are compared based on their keys, i.e. they must
495 * have the same keys and for each key the value must be equal according to the `Object.is()` algorithm. Non-object
496 * values are also compared with the same algorithm as `Object.is()`.
497 */
498export function shallowEqual<T>(left: T, right: any): boolean;
499
500/**
501 * A hook to access the redux `dispatch` function.
502 *
503 * Note for `redux-thunk` users: the return type of the returned `dispatch` functions for thunks is incorrect.
504 * However, it is possible to get a correctly typed `dispatch` function by creating your own custom hook typed
505 * from the store's dispatch function like this: `const useThunkDispatch = () => useDispatch<typeof store.dispatch>();`
506 *
507 * @returns redux store's `dispatch` function
508 *
509 * @example
510 *
511 * import React from 'react'
512 * import { useDispatch } from 'react-redux'
513 *
514 * export const CounterComponent = ({ value }) => {
515 * const dispatch = useDispatch()
516 * return (
517 * <div>
518 * <span>{value}</span>
519 * <button onClick={() => dispatch({ type: 'increase-counter' })}>
520 * Increase counter
521 * </button>
522 * </div>
523 * )
524 * }
525 */
526// NOTE: the first overload below and note above can be removed if redux-thunk typings add an overload for
527// the Dispatch function (see also this PR: https://github.com/reduxjs/redux-thunk/pull/247)
528export function useDispatch<TDispatch = Dispatch<any>>(): TDispatch;
529export function useDispatch<A extends Action = AnyAction>(): Dispatch<A>;
530
531/**
532 * A hook to access the redux store's state. This hook takes a selector function
533 * as an argument. The selector is called with the store state.
534 *
535 * This hook takes an optional equality comparison function as the second parameter
536 * that allows you to customize the way the selected state is compared to determine
537 * whether the component needs to be re-rendered.
538 *
539 * If you do not want to have to specify the root state type for whenever you use
540 * this hook with an inline selector you can use the `TypedUseSelectorHook` interface
541 * to create a version of this hook that is properly typed for your root state.
542 *
543 * @param selector the selector function
544 * @param equalityFn the function that will be used to determine equality
545 *
546 * @returns the selected state
547 *
548 * @example
549 *
550 * import React from 'react'
551 * import { useSelector } from 'react-redux'
552 * import { RootState } from './store'
553 *
554 * export const CounterComponent = () => {
555 * const counter = useSelector((state: RootState) => state.counter)
556 * return <div>{counter}</div>
557 * }
558 */
559export function useSelector<TState = DefaultRootState, TSelected = unknown>(
560 selector: (state: TState) => TSelected,
561 equalityFn?: (left: TSelected, right: TSelected) => boolean
562): TSelected;
563
564/**
565 * This interface allows you to easily create a hook that is properly typed for your
566 * store's root state.
567 *
568 * @example
569 *
570 * interface RootState {
571 * property: string;
572 * }
573 *
574 * const useTypedSelector: TypedUseSelectorHook<RootState> = useSelector;
575 *
576 */
577export interface TypedUseSelectorHook<TState> {
578 <TSelected>(
579 selector: (state: TState) => TSelected,
580 equalityFn?: (left: TSelected, right: TSelected) => boolean
581 ): TSelected;
582}
583
584/**
585 * A hook to access the redux store.
586 *
587 * @returns the redux store
588 *
589 * @example
590 *
591 * import React from 'react'
592 * import { useStore } from 'react-redux'
593 *
594 * export const ExampleComponent = () => {
595 * const store = useStore()
596 * return <div>{store.getState()}</div>
597 * }
598 */
599export function useStore<S = RootStateOrAny, A extends Action = AnyAction>(): Store<S, A>;
600
601/**
602 * Hook factory, which creates a `useSelector` hook bound to a given context.
603 *
604 * @param Context passed to your `<Provider>`.
605 * @returns A `useSelector` hook bound to the specified context.
606 */
607export function createSelectorHook(context?: Context<ReactReduxContextValue>): typeof useSelector;
608
609/**
610 * Hook factory, which creates a `useStore` hook bound to a given context.
611 *
612 * @param Context passed to your `<Provider>`.
613 * @returns A `useStore` hook bound to the specified context.
614 */
615export function createStoreHook(context?: Context<ReactReduxContextValue>): typeof useStore;
616
617/**
618 * Hook factory, which creates a `useDispatch` hook bound to a given context.
619 *
620 * @param Context passed to your `<Provider>`.
621 * @returns A `useDispatch` hook bound to the specified context.
622 */
623export function createDispatchHook(context?: Context<ReactReduxContextValue>): typeof useDispatch;
624
625// tslint:enable:no-unnecessary-generics