UNPKG

28.9 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// Curits Layne <https://github.com/clayne11>
5// Frank Tan <https://github.com/tansongyang>
6// Nicholas Boll <https://github.com/nicholasboll>
7// Dibyo Majumdar <https://github.com/mdibyo>
8// Valentin Descamps <https://github.com/val1984>
9// Johann Rakotoharisoa <https://github.com/jrakotoharisoa>
10// Anatoli Papirovski <https://github.com/apapirovski>
11// Boris Sergeyev <https://github.com/surgeboris>
12// Søren Bruus Frank <https://github.com/soerenbf>
13// Jonathan Ziller <https://github.com/mrwolfz>
14// Dylan Vann <https://github.com/dylanvann>
15// Yuki Ito <https://github.com/Lazyuki>
16// Kazuma Ebina <https://github.com/kazuma1989>
17// Michael Lebedev <https://github.com/megazazik>
18// jun-sheaf <https://github.com/jun-sheaf>
19// Lenz Weber <https://github.com/phryneas>
20// Mark Erikson <https://github.com/markerikson>
21// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
22// TypeScript Version: 3.0
23
24import {
25 ClassAttributes,
26 Component,
27 ComponentClass,
28 ComponentType,
29 FunctionComponent,
30 Context,
31 NamedExoticComponent,
32 ReactNode
33} from 'react';
34
35import {
36 Action,
37 ActionCreator,
38 AnyAction,
39 Dispatch,
40 Store
41} from 'redux';
42
43import hoistNonReactStatics = require('hoist-non-react-statics');
44
45/**
46 * This interface can be augmented by users to add default types for the root state when
47 * using `react-redux`.
48 * Use module augmentation to append your own type definition in a your_custom_type.d.ts file.
49 * https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
50 */
51// tslint:disable-next-line:no-empty-interface
52export interface DefaultRootState {}
53
54export type AnyIfEmpty<T extends object> = keyof T extends never ? any : T;
55export type RootStateOrAny = AnyIfEmpty<DefaultRootState>;
56
57// Omit taken from https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
58export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
59
60export type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;
61
62export interface DispatchProp<A extends Action = AnyAction> {
63 dispatch: Dispatch<A>;
64}
65
66export type AdvancedComponentDecorator<TProps, TOwnProps> =
67 (component: ComponentType<TProps>) => NamedExoticComponent<TOwnProps>;
68
69/**
70 * A property P will be present if:
71 * - it is present in DecorationTargetProps
72 *
73 * Its value will be dependent on the following conditions
74 * - if property P is present in InjectedProps and its definition extends the definition
75 * in DecorationTargetProps, then its definition will be that of DecorationTargetProps[P]
76 * - if property P is not present in InjectedProps then its definition will be that of
77 * DecorationTargetProps[P]
78 * - if property P is present in InjectedProps but does not extend the
79 * DecorationTargetProps[P] definition, its definition will be that of InjectedProps[P]
80 */
81export type Matching<InjectedProps, DecorationTargetProps> = {
82 [P in keyof DecorationTargetProps]: P extends keyof InjectedProps
83 ? InjectedProps[P] extends DecorationTargetProps[P]
84 ? DecorationTargetProps[P]
85 : InjectedProps[P]
86 : DecorationTargetProps[P];
87};
88
89/**
90 * a property P will be present if :
91 * - it is present in both DecorationTargetProps and InjectedProps
92 * - InjectedProps[P] can satisfy DecorationTargetProps[P]
93 * ie: decorated component can accept more types than decorator is injecting
94 *
95 * For decoration, inject props or ownProps are all optionally
96 * required by the decorated (right hand side) component.
97 * But any property required by the decorated component must be satisfied by the injected property.
98 */
99export type Shared<
100 InjectedProps,
101 DecorationTargetProps
102 > = {
103 [P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]?: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
104 };
105
106// Infers prop type from component C
107export type GetProps<C> = C extends ComponentType<infer P>
108 ? C extends ComponentClass<P> ? ClassAttributes<InstanceType<C>> & P : P
109 : never;
110
111// Applies LibraryManagedAttributes (proper handling of defaultProps
112// and propTypes).
113export type GetLibraryManagedProps<C> = JSX.LibraryManagedAttributes<C, GetProps<C>>;
114
115// Defines WrappedComponent and derives non-react statics.
116export type ConnectedComponent<
117 C extends ComponentType<any>,
118 P
119> = NamedExoticComponent<P> & hoistNonReactStatics.NonReactStatics<C> & {
120 WrappedComponent: C;
121};
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. Also adds new prop requirements from TNeedsProps.
126// Uses distributive omit to preserve discriminated unions part of original prop type
127export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> =
128 <C extends ComponentType<Matching<TInjectedProps, GetProps<C>>>>(
129 component: C
130 ) => ConnectedComponent<C, DistributiveOmit<GetLibraryManagedProps<C>, keyof Shared<TInjectedProps, GetLibraryManagedProps<C>>> & TNeedsProps>;
131
132// Injects props and removes them from the prop requirements.
133// Will not pass through the injected props if they are passed in during
134// render.
135export type InferableComponentEnhancer<TInjectedProps> =
136 InferableComponentEnhancerWithProps<TInjectedProps, {}>;
137
138export type InferThunkActionCreatorType<TActionCreator extends (...args: any[]) => any> =
139 TActionCreator extends (...args: infer TParams) => (...args: any[]) => infer TReturn
140 ? (...args: TParams) => TReturn
141 : TActionCreator;
142
143export type HandleThunkActionCreator<TActionCreator> =
144 TActionCreator extends (...args: any[]) => any
145 ? InferThunkActionCreatorType<TActionCreator>
146 : TActionCreator;
147
148// redux-thunk middleware returns thunk's return value from dispatch call
149// https://github.com/reduxjs/redux-thunk#composition
150export type ResolveThunks<TDispatchProps> =
151 TDispatchProps extends { [key: string]: any }
152 ? {
153 [C in keyof TDispatchProps]: HandleThunkActionCreator<TDispatchProps[C]>
154 }
155 : TDispatchProps;
156
157// the conditional type is to support TypeScript 3.0, which does not support mapping over tuples and arrays;
158// once the typings are updated to at least TypeScript 3.1, a simple mapped type can replace this mess
159export type ResolveArrayThunks<TDispatchProps extends ReadonlyArray<any>> =
160 TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7, infer A8, infer A9]
161 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>,
162 HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>, HandleThunkActionCreator<A7>, HandleThunkActionCreator<A8>, HandleThunkActionCreator<A9>]
163 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7, infer A8]
164 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>,
165 HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>, HandleThunkActionCreator<A7>, HandleThunkActionCreator<A8>]
166 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7]
167 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>,
168 HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>, HandleThunkActionCreator<A7>]
169 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5, infer A6]
170 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>, HandleThunkActionCreator<A5>, HandleThunkActionCreator<A6>]
171 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4, infer A5]
172 ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>, HandleThunkActionCreator<A5>]
173 : TDispatchProps extends [infer A1, infer A2, infer A3, infer A4] ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>, HandleThunkActionCreator<A4>]
174 : TDispatchProps extends [infer A1, infer A2, infer A3] ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>, HandleThunkActionCreator<A3>]
175 : TDispatchProps extends [infer A1, infer A2] ? [HandleThunkActionCreator<A1>, HandleThunkActionCreator<A2>]
176 : TDispatchProps extends [infer A1] ? [HandleThunkActionCreator<A1>]
177 : TDispatchProps extends Array<infer A> ? Array<HandleThunkActionCreator<A>>
178 : TDispatchProps extends ReadonlyArray<infer A> ? ReadonlyArray<HandleThunkActionCreator<A>>
179 : never
180 ;
181
182/**
183 * Connects a React component to a Redux store.
184 *
185 * - Without arguments, just wraps the component, without changing the behavior / props
186 *
187 * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior
188 * is to override ownProps (as stated in the docs), so what remains is everything that's
189 * not a state or dispatch prop
190 *
191 * - When 3rd param is passed, we don't know if ownProps propagate and whether they
192 * should be valid component props, because it depends on mergeProps implementation.
193 * As such, it is the user's responsibility to extend ownProps interface from state or
194 * dispatch props or both when applicable
195 *
196 * @param mapStateToProps
197 * @param mapDispatchToProps
198 * @param mergeProps
199 * @param options
200 */
201export interface Connect<DefaultState = DefaultRootState> {
202 // tslint:disable:no-unnecessary-generics
203 (): InferableComponentEnhancer<DispatchProp>;
204
205 <TStateProps = {}, no_dispatch = {}, TOwnProps = {}, State = DefaultState>(
206 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>
207 ): InferableComponentEnhancerWithProps<TStateProps & DispatchProp, TOwnProps>;
208
209 <no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
210 mapStateToProps: null | undefined,
211 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>
212 ): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
213
214 <no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
215 mapStateToProps: null | undefined,
216 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
217 ): InferableComponentEnhancerWithProps<
218 ResolveThunks<TDispatchProps>,
219 TOwnProps
220 >;
221
222 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
223 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
224 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>
225 ): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>;
226
227 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
228 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
229 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
230 ): InferableComponentEnhancerWithProps<
231 TStateProps & ResolveThunks<TDispatchProps>,
232 TOwnProps
233 >;
234
235 <no_state = {}, no_dispatch = {}, TOwnProps = {}, TMergedProps = {}>(
236 mapStateToProps: null | undefined,
237 mapDispatchToProps: null | undefined,
238 mergeProps: MergeProps<undefined, undefined, TOwnProps, TMergedProps>,
239 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
240
241 <TStateProps = {}, no_dispatch = {}, TOwnProps = {}, TMergedProps = {}, State = DefaultState>(
242 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
243 mapDispatchToProps: null | undefined,
244 mergeProps: MergeProps<TStateProps, undefined, TOwnProps, TMergedProps>,
245 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
246
247 <no_state = {}, TDispatchProps = {}, TOwnProps = {}, TMergedProps = {}>(
248 mapStateToProps: null | undefined,
249 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
250 mergeProps: MergeProps<undefined, TDispatchProps, TOwnProps, TMergedProps>,
251 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
252
253 <TStateProps = {}, no_dispatch = {}, TOwnProps = {}, State = DefaultState>(
254 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
255 mapDispatchToProps: null | undefined,
256 mergeProps: null | undefined,
257 options: Options<State, TStateProps, TOwnProps>
258 ): InferableComponentEnhancerWithProps<DispatchProp & TStateProps, TOwnProps>;
259
260 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
261 mapStateToProps: null | undefined,
262 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>,
263 mergeProps: null | undefined,
264 options: Options<{}, TStateProps, TOwnProps>
265 ): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
266
267 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
268 mapStateToProps: null | undefined,
269 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
270 mergeProps: null | undefined,
271 options: Options<{}, TStateProps, TOwnProps>
272 ): InferableComponentEnhancerWithProps<
273 ResolveThunks<TDispatchProps>,
274 TOwnProps
275 >;
276
277 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
278 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
279 mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>,
280 mergeProps: null | undefined,
281 options: Options<State, TStateProps, TOwnProps>
282 ): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>;
283
284 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
285 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
286 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
287 mergeProps: null | undefined,
288 options: Options<State, TStateProps, TOwnProps>
289 ): InferableComponentEnhancerWithProps<
290 TStateProps & ResolveThunks<TDispatchProps>,
291 TOwnProps
292 >;
293
294 <TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, TMergedProps = {}, State = DefaultState>(
295 mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
296 mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
297 mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
298 options?: Options<State, TStateProps, TOwnProps, TMergedProps>
299 ): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
300 // tslint:enable:no-unnecessary-generics
301}
302
303/**
304 * Infers the type of props that a connector will inject into a component.
305 */
306export type ConnectedProps<TConnector> =
307 TConnector extends InferableComponentEnhancerWithProps<infer TInjectedProps, any>
308 ? unknown extends TInjectedProps
309 ? TConnector extends InferableComponentEnhancer<infer TInjectedProps>
310 ? TInjectedProps
311 : never
312 : TInjectedProps
313 : never;
314
315/**
316 * The connect function. See {@type Connect} for details.
317 */
318export const connect: Connect;
319
320export type MapStateToProps<TStateProps, TOwnProps, State = DefaultRootState> =
321 (state: State, ownProps: TOwnProps) => TStateProps;
322
323export type MapStateToPropsFactory<TStateProps, TOwnProps, State = DefaultRootState> =
324 (initialState: State, ownProps: TOwnProps) => MapStateToProps<TStateProps, TOwnProps, State>;
325
326export type MapStateToPropsParam<TStateProps, TOwnProps, State = DefaultRootState> =
327 MapStateToPropsFactory<TStateProps, TOwnProps, State> | MapStateToProps<TStateProps, TOwnProps, State> | null | undefined;
328
329export type MapDispatchToPropsFunction<TDispatchProps, TOwnProps> =
330 (dispatch: Dispatch<Action>, ownProps: TOwnProps) => TDispatchProps;
331
332export type MapDispatchToProps<TDispatchProps, TOwnProps> =
333 MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | TDispatchProps;
334
335export type MapDispatchToPropsFactory<TDispatchProps, TOwnProps> =
336 (dispatch: Dispatch<Action>, ownProps: TOwnProps) => MapDispatchToPropsFunction<TDispatchProps, TOwnProps>;
337
338export type MapDispatchToPropsParam<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToProps<TDispatchProps, TOwnProps>;
339
340export type MapDispatchToPropsNonObject<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToPropsFunction<TDispatchProps, TOwnProps>;
341
342export type MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> =
343 (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps) => TMergedProps;
344
345export interface Options<State = DefaultRootState, TStateProps = {}, TOwnProps = {}, TMergedProps = {}> extends ConnectOptions {
346 /**
347 * If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps,
348 * preventing unnecessary updates, assuming that the component is a “pure” component
349 * and does not rely on any input or state other than its props and the selected Redux store’s state.
350 * Defaults to true.
351 * @default true
352 */
353 pure?: boolean | undefined;
354
355 /**
356 * When pure, compares incoming store state to its previous value.
357 * @default strictEqual
358 */
359 areStatesEqual?: ((nextState: State, prevState: State) => boolean) | undefined;
360
361 /**
362 * When pure, compares incoming props to its previous value.
363 * @default shallowEqual
364 */
365 areOwnPropsEqual?: ((nextOwnProps: TOwnProps, prevOwnProps: TOwnProps) => boolean) | undefined;
366
367 /**
368 * When pure, compares the result of mapStateToProps to its previous value.
369 * @default shallowEqual
370 */
371 areStatePropsEqual?: ((nextStateProps: TStateProps, prevStateProps: TStateProps) => boolean) | undefined;
372
373 /**
374 * When pure, compares the result of mergeProps to its previous value.
375 * @default shallowEqual
376 */
377 areMergedPropsEqual?: ((nextMergedProps: TMergedProps, prevMergedProps: TMergedProps) => boolean) | undefined;
378
379 /**
380 * If true, use React's forwardRef to expose a ref of the wrapped component
381 *
382 * @default false
383 */
384 forwardRef?: boolean | undefined;
385}
386
387/**
388 * Connects a React component to a Redux store. It is the base for {@link connect} but is less opinionated about
389 * how to combine <code>state</code>, <code>props</code>, and <code>dispatch</code> into your final props. It makes no
390 * assumptions about defaults or memoization of results, leaving those responsibilities to the caller.It does not
391 * modify the component class passed to it; instead, it returns a new, connected component for you to use.
392 *
393 * @param selectorFactory The selector factory. See SelectorFactory type for details.
394 * @param connectOptions If specified, further customizes the behavior of the connector. Additionally, any extra
395 * options will be passed through to your <code>selectorFactory</code> in the <code>factoryOptions</code> argument.
396 */
397export function connectAdvanced<S, TProps, TOwnProps, TFactoryOptions = {}>(
398 // tslint:disable-next-line no-unnecessary-generics
399 selectorFactory: SelectorFactory<S, TProps, TOwnProps, TFactoryOptions>,
400 connectOptions?: ConnectOptions & TFactoryOptions
401): AdvancedComponentDecorator<TProps, TOwnProps>;
402
403/**
404 * Initializes a selector function (during each instance's constructor). That selector function is called any time the
405 * connector component needs to compute new props, as a result of a store state change or receiving new props. The
406 * result of <code>selector</code> is expected to be a plain object, which is passed as the props to the wrapped
407 * component. If a consecutive call to <code>selector</code> returns the same object (<code>===</code>) as its previous
408 * call, the component will not be re-rendered. It's the responsibility of <code>selector</code> to return that
409 * previous object when appropriate.
410 */
411export type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> =
412 (dispatch: Dispatch<Action>, factoryOptions: TFactoryOptions) => Selector<S, TProps, TOwnProps>;
413
414export type Selector<S, TProps, TOwnProps = null> = TOwnProps extends null | undefined
415 ? (state: S) => TProps
416 : (state: S, ownProps: TOwnProps) => TProps;
417
418export interface ConnectOptions {
419 /**
420 * Computes the connector component's displayName property relative to that of the wrapped component. Usually
421 * overridden by wrapper functions.
422 *
423 * @default name => 'ConnectAdvanced('+name+')'
424 * @param componentName
425 */
426 getDisplayName?: ((componentName: string) => string) | undefined;
427 /**
428 * Shown in error messages. Usually overridden by wrapper functions.
429 *
430 * @default 'connectAdvanced'
431 */
432 methodName?: string | undefined;
433 /**
434 * If defined, a property named this value will be added to the props passed to the wrapped component. Its value
435 * will be the number of times the component has been rendered, which can be useful for tracking down unnecessary
436 * re-renders.
437 *
438 * @default undefined
439 */
440 renderCountProp?: string | undefined;
441 /**
442 * Controls whether the connector component subscribes to redux store state changes. If set to false, it will only
443 * re-render on <code>componentWillReceiveProps</code>.
444 *
445 * @default true
446 */
447 shouldHandleStateChanges?: boolean | undefined;
448 /**
449 * The key of props/context to get the store. You probably only need this if you are in the inadvisable position of
450 * having multiple stores.
451 *
452 * @default 'store'
453 */
454 storeKey?: string | undefined;
455 /**
456 * @deprecated Use forwardRef
457 *
458 * @default false
459 */
460 withRef?: boolean | undefined;
461 /**
462 * The react context to get the store from.
463 *
464 * @default ReactReduxContext
465 */
466 context?: Context<ReactReduxContextValue> | undefined;
467}
468
469export interface ReactReduxContextValue<SS = any, A extends Action = AnyAction> {
470 store: Store<SS, A>;
471 storeState: SS;
472}
473
474export interface ProviderProps<A extends Action = AnyAction> {
475 /**
476 * The single Redux store in your application.
477 */
478 store: Store<any, A>;
479 /**
480 * Optional context to be used internally in react-redux. Use React.createContext() to create a context to be used.
481 * If this is used, generate own connect HOC by using connectAdvanced, supplying the same context provided to the
482 * Provider. Initial value doesn't matter, as it is overwritten with the internal state of Provider.
483 */
484 context?: Context<ReactReduxContextValue> | undefined;
485 children?: ReactNode;
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