Skip to content

Commit a0a0cff

Browse files
committed
Merge branch 'experimental' of https://github.com/uidotdev/usehooks into experimental
2 parents ce0aedc + 6ffa8e7 commit a0a0cff

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

index.d.ts

+68-8
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,34 @@ declare module "@uidotdev/usehooks" {
128128
(value: string) => Promise<void>
129129
];
130130

131+
export function useContinuousRetry(
132+
callback: () => any,
133+
interval?: number,
134+
options?: {
135+
maxRetries?: number
136+
}): boolean;
137+
138+
export function useCountdown(endTime: number, options: {
139+
interval: number,
140+
onComplete: () => any,
141+
onTick: () => any
142+
}): number;
143+
131144
export function useCounter(
132145
startingValue?: number,
133146
options?: {
134147
min?: number;
135148
max?: number;
136149
}
137150
): [
138-
number,
139-
{
140-
increment: () => void;
141-
decrement: () => void;
142-
set: (nextCount: number) => void;
143-
reset: () => void;
144-
}
145-
];
151+
number,
152+
{
153+
increment: () => void;
154+
decrement: () => void;
155+
set: (nextCount: number) => void;
156+
reset: () => void;
157+
}
158+
];
146159

147160
export function useDebounce<T>(value: T, delay: number): T;
148161

@@ -153,8 +166,25 @@ declare module "@uidotdev/usehooks" {
153166

154167
export function useDocumentTitle(title: string): void;
155168

169+
export function useEventListener(
170+
target: React.MutableRefObject<Element> | Element,
171+
eventName: string,
172+
handler: (Event) => any,
173+
options?: {
174+
capture?: boolean,
175+
passive?: boolean,
176+
once?: boolean
177+
}): void;
178+
156179
export function useFavicon(url: string): void;
157180

181+
export function useFetch(
182+
url: string,
183+
options?: {}): {
184+
error: Error | undefined,
185+
data: any | undefined
186+
}
187+
158188
export function useGeolocation(options?: PositionOptions): GeolocationState;
159189

160190
export function useHistoryState<T>(initialPresent?: T): HistoryState<T>;
@@ -170,10 +200,29 @@ declare module "@uidotdev/usehooks" {
170200
options?: IntersectionObserverInit
171201
): [React.MutableRefObject<T>, IntersectionObserverEntry | null];
172202

203+
export function useInterval(cb: () => any, ms: number): () => void;
204+
205+
export function useIntervalWhen(
206+
cb: () => any,
207+
options: {
208+
ms: number,
209+
when: boolean,
210+
startImmediately?: boolean
211+
}): () => void;
212+
173213
export function useIsClient(): boolean;
174214

175215
export function useIsFirstRender(): boolean;
176216

217+
export function useKeyPress(
218+
key: string,
219+
cb: (Event) => any,
220+
options?: {
221+
event?: string,
222+
target?: Element | Window,
223+
eventOptions?: {}
224+
}): void;
225+
177226
export function useList<T>(defaultList?: T[]): [T[], CustomList<T>];
178227

179228
export function useLocalStorage<T>(
@@ -183,6 +232,8 @@ declare module "@uidotdev/usehooks" {
183232

184233
export function useLockBodyScroll(): void;
185234

235+
export function useLogger(name: string, ...rest: any[]): void;
236+
186237
export function useLongPress(
187238
callback: (e: Event) => void,
188239
options?: LongPressOptions
@@ -214,12 +265,19 @@ declare module "@uidotdev/usehooks" {
214265
type: string;
215266
};
216267

268+
export function usePageLeave(cb: () => any): void;
269+
217270
export function usePreferredLanguage(): string;
218271

219272
export function usePrevious<T>(newValue: T): T;
220273

221274
export function useQueue<T>(initialValue?: T[]): CustomQueue<T>;
222275

276+
export function useRandomInterval(cb: () => any, options: {
277+
minDelay: number,
278+
maxDelay: number
279+
}): () => void;
280+
223281
export function useRenderCount(): number;
224282

225283
export function useRenderInfo(name?: string): RenderInfo | undefined;
@@ -242,6 +300,8 @@ declare module "@uidotdev/usehooks" {
242300

243301
export function useThrottle<T>(value: T, delay: number): T;
244302

303+
export function useTimeout(cb: () => any, ms: number): () => void;
304+
245305
export function useToggle(
246306
initialValue?: boolean
247307
): [boolean, (newValue?: boolean) => void];

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uidotdev/usehooks",
3-
"version": "2.1.1-experimental.1",
3+
"version": "2.3.1-experimental.1",
44
"description": "A collection of modern, server-safe React hooks – from the ui.dev team",
55
"type": "module",
66
"repository": "uidotdev/usehooks",

0 commit comments

Comments
 (0)