This repository has been archived by the owner on Nov 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
/
index.js.flow
60 lines (53 loc) · 1.64 KB
/
index.js.flow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @flow
* @format
*/
// This comes straight from the Redux types.
type ActionType = {+type: string & any};
export type ReduxReactHooks<
TState,
TAction: ActionType,
TDispatch,
TStore: Store<TState, TAction, TDispatch>,
> = {|
+StoreContext: Context<?TStore>,
+useMappedState: <TResult>(
mapState: (state: TState) => TResult,
equalityCheck?: (TResult, TResult) => boolean,
) => TResult,
+useDispatch: () => TDispatch,
|};
type CreateOptions = {|
defaultEqualityCheck?: (a: mixed, b: mixed) => boolean,
|};
/**
* To use redux-react-hook with stronger type safety, or to use with multiple
* stores in the same app, create() your own instance and re-export the returned
* functions.
*/
declare export function create<
TState,
TAction: ActionType,
TDispatch,
TStore: Store<TState, TAction, TDispatch>,
>(options?: CreateOptions): ReduxReactHooks<TState, TAction, TDispatch, TStore>;
// This is a module variable, so it cannot be typed generic.
declare export var StoreContext: Context<any>;
declare export function useDispatch<TDispatch>(): TDispatch;
/**
* Your passed in mapState function should be memoized with useCallback to avoid
* resubscribing every render. If you don't use other props in mapState, pass
* an empty array [] as the dependency list so the callback isn't recreated
* every render.
*
* const todo = useMappedState(useCallback(
* state => state.todos.get(id),
* [id],
* ));
*/
declare export function useMappedState<TState, TResult>(
mapState: (state: TState) => TResult,
equalityCheck?: (TResult, TResult) => boolean,
): TResult;