Skip to content

Commit 9eab146

Browse files
committed
[FIX] rename useRequestIdleCallback hook to useIdle
1 parent 02d82dc commit 9eab146

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

apps/react-tools-demo/src/components/hooks/useRequestIdleCallback/UseRequestIdleCallback.tsx renamed to apps/react-tools-demo/src/components/hooks/useIdle/UseIdle.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { useState } from "react"
2-
import { useRequestIdleCallback } from "../../../../../../packages/react-tools/src";
2+
import { useIdle } from "../../../../../../packages/react-tools/src";
33

44

55
/**
66
The component has:
77
- a __iterations__ variable of type string.
88
- a __log__ variable of type string.
9-
- a function __invoke__ returned from _useRequestIdleCallback_ hook, initialized with a cb that update __log__ variable with message _"RequestIdleCallback executed"_.
9+
- a function __invoke__ returned from _useIdle_ hook, initialized with a cb that update __log__ variable with message _"RequestIdleCallback executed"_.
1010
- a button start that when clicked executes __start__ function that executes __invoke__ function and updates __iterations__ variable inside a loop with iteration index.
1111
*/
12-
export const UseRequestIdleCallback = () => {
12+
export const UseIdle = () => {
1313
const [iterations, setIterations] = useState(0);
1414
const [log, setLog] = useState("");
15-
const [invoke] = useRequestIdleCallback(() => setLog("RequestIdleCallback executed"));
15+
const [invoke] = useIdle(() => setLog("RequestIdleCallback executed"));
1616

1717
const start = async() => {
1818
invoke();

apps/react-tools-demo/src/constants/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const COMPONENTS = [
7070
"useMediaQuery",
7171
"useColorScheme",
7272
"useTitle",
73-
"useRequestIdleCallback"
73+
"useIdle"
7474
]
7575
],
7676
//UTILS

packages/react-tools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
- [x] useMediaQuery
8383
- [x] useColorScheme
8484
- [x] useTitle (change document.title but also document.head.title nodeElement)
85-
- [x] useRequestIdleCallback
85+
- [x] useIdle
8686
- [ ] useFullscreen (check browser compatibility)
8787
- [ ] useLanguage (?)
8888
- [ ] useScreenShare

packages/react-tools/src/hooks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ export { useIsOnline } from './useIsOnline';
5151
export { useResizeObserver } from './useResizeObserver';
5252
export { useIntersectionObserver } from './useIntersectionObserver';
5353
export { useMutationObserver } from './useMutationObserver';
54-
export { useRequestIdleCallback } from './useRequestIdleCallback';
54+
export { useIdle } from './useIdle';

packages/react-tools/src/hooks/useRequestIdleCallback.ts renamed to packages/react-tools/src/hooks/useIdle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useCallback, useRef } from "react"
22

33
/**
4-
* **`useRequestIdleCallback`**: Hook to use [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) in React. The __options__ parameter differs from _IdleRequestOptions_ type: it adds the possibility to pass another property __unsupportedBehavior__ to specify what do if requestIdleCallback is not supported.
4+
* **`useIdle`**: Hook to invoke a callback when the browser is idle. Refer to [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) in React. The __options__ parameter differs from _IdleRequestOptions_ type: it adds the possibility to pass another property __unsupportedBehavior__ to specify what do if requestIdleCallback is not supported.
55
* @param {(deadline?: IdleDeadline | DOMHighResTimeStamp | void)=> void} cb -callback that should be called in the near future.
66
* @param {IdleRequestOptions & { unsupportedBehavior: "animationFrame"|"timeout"|"immediatly" }} [opts] - Contains optional configuration parameters.
77
* @returns {[()=>void, ()=>void]} result - array where functions to invoke and cancel execution.
88
*/
9-
export const useRequestIdleCallback = (cb: (deadline?: IdleDeadline | DOMHighResTimeStamp | void) => void, opts?: {timeout: number , unsupportedBehavior?: "animationFrame" | "timeout" | "immediatly" }): [() => void, () => void] => {
9+
export const useIdle = (cb: (deadline?: IdleDeadline | DOMHighResTimeStamp | void) => void, opts?: {timeout: number , unsupportedBehavior?: "animationFrame" | "timeout" | "immediatly" }): [() => void, () => void] => {
1010
const {timeout, unsupportedBehavior} = opts || {};
1111
const idRequest = useRef<number|null>();
1212

packages/react-tools/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export {
6565
useResizeObserver,
6666
useIntersectionObserver,
6767
useMutationObserver,
68-
useRequestIdleCallback
68+
useIdle
6969
} from './hooks'
7070

7171
export {

0 commit comments

Comments
 (0)