Skip to content

Commit 8347e75

Browse files
committed
Fix timeout hook documentation
1 parent 0af2cbd commit 8347e75

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

templates/admin/src/lib/plume-http-react-hook-loader/observableLoaderHook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function useObservableLoaderConfigurable<T extends ObservableDataHandler<
109109
.map((dataObservable: ObservableDataHandler<any>) => {
110110
// the number of observable sources is fixed and cannot change,
111111
// so the number of time useObservable is called will be stable
112-
// eslint-disable-next-line @typescript-eslint/no-explicit-any,react-hooks/rules-of-hooks
112+
// eslint-disable-next-line react-hooks/rules-of-hooks
113113
const data: T = useObservable(dataObservable.dataObservable);
114114

115115
return {
@@ -180,6 +180,7 @@ export function useObservableLoader<T extends ObservableDataHandler<any>[]>(
180180
) : DataLoader<unknown[]> {
181181
return useObservableLoaderConfigurable({
182182
observableSources,
183+
// eslint-disable-next-line react-hooks/exhaustive-deps
183184
useOnComponentMountedHook: (onMounted: () => void) => useEffectWithSsrSupport(onMounted, dependencies),
184185
});
185186
}

templates/admin/src/lib/plume-http-react-hook-loader/timeoutHook.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ export type TimeoutController = {
1818
};
1919

2020
type TimeoutType = ReturnType<typeof setTimeout>;
21+
2122
/**
2223
* This hook enables to use safely {@link setTimeout} in a component.
2324
* The issue using raw {@link setTimeout} is that it can resolve after the component has been unmounted...
2425
* This can create lots of very difficult bugs.
2526
*
2627
* This hook makes sure to stop/unregister the {@link setTimeout} when the component is being unmounted.
2728
* @param callback The function that will be called after {@link delayInMillis} time has passed.
29+
* If the callback changes over time, the callback called after the timeout will be the changed one.
30+
* If the timeout has already passed, the callback changes will have no impact.
2831
* @param delayInMillis The delay in milliseconds after which the {@link callback} will be executed.
32+
* Delay changes after the first call will be ignored.
2933
*
3034
* This hook is a typed and commented version of
3135
* https://github.com/WebDevSimplified/useful-custom-react-hooks/blob/main/src/2-useTimeout/useTimeout.js
@@ -54,8 +58,6 @@ export default function useTimeout(callback: () => void, delayInMillis: number)
5458
return stopTimeout;
5559
// eslint-disable-next-line react-hooks/exhaustive-deps
5660
}, []);
57-
// delayInMillis is not in the dependencies. If it changes at runtime, we do not want to reset the hook.
58-
// If delay can change at runtime, this hook is not the best solution to use.
5961

6062
const restartTimeout = () => {
6163
stopTimeout();

templates/front/src/lib/plume-http-react-hook-loader/observableLoaderHook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function useObservableLoaderConfigurable<T extends ObservableDataHandler<
109109
.map((dataObservable: ObservableDataHandler<any>) => {
110110
// the number of observable sources is fixed and cannot change,
111111
// so the number of time useObservable is called will be stable
112-
// eslint-disable-next-line @typescript-eslint/no-explicit-any,react-hooks/rules-of-hooks
112+
// eslint-disable-next-line react-hooks/rules-of-hooks
113113
const data: T = useObservable(dataObservable.dataObservable);
114114

115115
return {
@@ -180,6 +180,7 @@ export function useObservableLoader<T extends ObservableDataHandler<any>[]>(
180180
) : DataLoader<unknown[]> {
181181
return useObservableLoaderConfigurable({
182182
observableSources,
183+
// eslint-disable-next-line react-hooks/exhaustive-deps
183184
useOnComponentMountedHook: (onMounted: () => void) => useEffectWithSsrSupport(onMounted, dependencies),
184185
});
185186
}

templates/front/src/lib/plume-http-react-hook-loader/timeoutHook.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ type TimeoutType = ReturnType<typeof setTimeout>;
2626
*
2727
* This hook makes sure to stop/unregister the {@link setTimeout} when the component is being unmounted.
2828
* @param callback The function that will be called after {@link delayInMillis} time has passed.
29+
* If the callback changes over time, the callback called after the timeout will be the changed one.
30+
* If the timeout has already passed, the callback changes will have no impact.
2931
* @param delayInMillis The delay in milliseconds after which the {@link callback} will be executed.
32+
* Delay changes after the first call will be ignored.
3033
*
3134
* This hook is a typed and commented version of
3235
* https://github.com/WebDevSimplified/useful-custom-react-hooks/blob/main/src/2-useTimeout/useTimeout.js
@@ -55,8 +58,6 @@ export default function useTimeout(callback: () => void, delayInMillis: number)
5558
return stopTimeout;
5659
// eslint-disable-next-line react-hooks/exhaustive-deps
5760
}, []);
58-
// delayInMillis is not in the dependencies. If it changes at runtime, we do not want to reset the hook.
59-
// If delay can change at runtime, this hook is not the best solution to use.
6061

6162
const restartTimeout = () => {
6263
stopTimeout();

0 commit comments

Comments
 (0)