UNPKG

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