forked from antonioru/beautiful-react-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
222 lines (184 loc) · 5.26 KB
/
index.d.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import {MutableRefObject, EffectCallback, DependencyList, Dispatch, SetStateAction} from 'react';
type ThrottleOrDebounceOpts = {
leading: boolean,
trailing: boolean,
}
type TimeoutOrIntervalOpts = {
cancelOnUnmount: boolean,
}
type EventListenerOptions = {
capture: boolean,
once: boolean,
passive: boolean,
}
type HandlerSetter = (...parameters: Array<any>) => unknown;
type Cancelable = {
cancel(): void;
flush(): void;
}
/**
* useDebouncedFn
*/
export declare const useDebouncedFn: (fn: Function, wait?: number, options?: ThrottleOrDebounceOpts, dependencies?: DependencyList) => Cancelable;
/**
* useDidMount
*/
export declare const useDidMount: (handler: Function) => HandlerSetter;
/**
* useGeolocation
*/
export declare const useGeolocation: (options?: PositionOptions) => [GeolocationState, GeolocationCallbackSetters];
/**
* useGeolocationEvents
*/
type GeolocationCallbackSetters = {
isSupported: boolean,
onChange: HandlerSetter,
onError: HandlerSetter,
}
export declare const useGeolocationEvents: (options?: PositionOptions) => GeolocationCallbackSetters;
/**
* useGeolocationState
*/
type GeolocationState = {
isSupported: boolean,
isRetrieving: boolean,
position: {
timestamp: number,
coords: {
latitude: number,
longitude: number,
altitude: number,
accuracy: number,
altitudeAccuracy: number,
heading: number,
speed: number,
},
}
}
export declare const useGeolocationState: (options?: PositionOptions) => GeolocationState;
/**
* useGlobalEvent
*/
export declare const useGlobalEvent: (eventName: string, options?: EventListenerOptions, handler?: Function) => HandlerSetter;
/**
* useInterval
*/
export declare const useInterval: (fn: Function, milliseconds: number, options?: TimeoutOrIntervalOpts) => [boolean, EffectCallback];
/**
* useLifecycle
*/
export declare const useLifecycle: (mount: Function, unmount: Function) => { onDidMount: HandlerSetter, onWillUnmount: HandlerSetter };
/**
* useMediaQuery
*/
export declare const useMediaQuery: (mediaQuery: string) => boolean;
/**
* useOnlineState
*/
export declare const useOnlineState: () => boolean;
/**
* useViewportSpy
*/
export declare const useViewportSpy: (elementRef: MutableRefObject<HTMLElement>, options?: IntersectionObserverInit) => boolean;
/**
* useValidatedState
*/
export declare const useValidatedState: (validator: Function, initialState?: any) => [
any,
Dispatch<SetStateAction<any>>,
{ changed: boolean, valid: boolean }
];
/**
* useDrag
*/
type DragOptions = {
dragImage?: string,
dragImageXOffset?: number,
dragImageYOffset?: number,
transfer?: object | string | number,
transferFormat: 'text' | 'text/plain',
};
export declare const useDrag: (ref: MutableRefObject<MouseTarget>, options: DragOptions) => boolean;
/**
* useDragEvents
*/
export declare const useDragEvents: (ref: MutableRefObject<MouseTarget>, setDraggable?: boolean) => ({
onDrag: HandlerSetter,
onDrop: HandlerSetter,
onDragEnter: HandlerSetter,
onDragEnd: HandlerSetter,
onDragExit: HandlerSetter,
onDragLeave: HandlerSetter,
onDragOver: HandlerSetter,
onDragStart: HandlerSetter,
});
/**
* useMouse
*/
export declare const useMouse: (ref?: MutableRefObject<MouseTarget>) => [MouseState, MouseCallbackSetters];
/**
* useMouseEvents
*/
type MouseTarget = HTMLElement | Document | Window;
type MouseCallbackSetters = {
onMouseDown: HandlerSetter,
onMouseEnter: HandlerSetter,
onMouseLeave: HandlerSetter,
onMouseMove: HandlerSetter,
onMouseOut: HandlerSetter,
onMouseOver: HandlerSetter,
onMouseUp: HandlerSetter,
}
export declare const useMouseEvents: (ref?: MutableRefObject<MouseTarget>) => MouseCallbackSetters;
/**
* useMouseState
*/
type MouseState = {
clientX: number,
clientY: number,
screenX: number,
screenY: number,
}
export declare const useMouseState: (ref?: MutableRefObject<MouseTarget>) => MouseState;
/**
* usePreviousValue
*/
export declare const usePreviousValue: (value: any) => any;
/**
* useThrottledFn
*/
export declare const useThrottledFn: (fn: Function, wait?: number, options?: ThrottleOrDebounceOpts, dependencies?: DependencyList) => Cancelable;
/**
* useTimeout
*/
export declare const useTimeout: (fn: Function, milliseconds: number, options?: TimeoutOrIntervalOpts) => [boolean, EffectCallback];
/**
* useConditionalTimeout
*/
export declare const useConditionalTimeout: (fn: Function, milliseconds: number, condition: boolean, options?: TimeoutOrIntervalOpts) => [boolean, EffectCallback];
/**
* useValueHistory
*/
export declare const useValueHistory: (value: any) => Array<any>;
/**
* useWillUnmount
*/
export declare const useWillUnmount: (handler?: Function) => HandlerSetter;
/**
* useWindowResize
*/
export declare const useWindowResize: (handler: Function) => HandlerSetter;
/**
* useWindowScroll
*/
export declare const useWindowScroll: (handler: Function) => HandlerSetter;
/**
* useRequestAnimationFrame
*/
type UseRequestAnimationFrameOptions = { increment: number, startAt: number, finishAt: number };
export declare const useRequestAnimationFrame: (func: Function, options?: UseRequestAnimationFrameOptions) => HandlerSetter;
/**
* useLocalStorage
*/
export declare const useLocalStorage: (localStorageKey:any, defaultValue: any) => [any, HandlerSetter];