Skip to content

Commit 743eea9

Browse files
committed
feat: 🎸 Major update
BREAKING CHANGE: 🧨 structure and hooks names changes
1 parent 64e563d commit 743eea9

24 files changed

+92
-41
lines changed

src/hooks/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export * from "./use-deps-change";
2+
export * from "./use-did-mount";
3+
export * from "./use-did-update";
4+
export * from "./use-force-update";
5+
export * from "./use-is-mounted";
6+
export * from "./use-layout-mount";
7+
export * from "./use-layout-update";
8+
export * from "./use-will-mount";
9+
export * from "./use-will-unmount";

src/hooks/use-deps-change/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-deps-change.hook";

src/hooks/use-did-change.hook.ts renamed to src/hooks/use-deps-change/use-deps-change.hook.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useRef } from "react";
22

3-
export const useDidChange = <T extends unknown[]>(
4-
callback: (previousDependencies: T | null) => void,
3+
export const useDepsChange = <T extends any[]>(
4+
callback: VoidFunction | ((previousDependencies: T | null) => VoidFunction),
55
dependencies: T,
66
useOnMount = false,
77
) => {

src/hooks/use-did-mount.hook.ts

-6
This file was deleted.

src/hooks/use-did-mount/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-did-mount.hook";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable react-hooks/exhaustive-deps */
2+
import { useEffect, useRef } from "react";
3+
4+
export const useDidMount = (callback: VoidFunction | (() => VoidFunction)) => {
5+
const mounted = useRef(false);
6+
7+
useEffect(() => {
8+
if (!mounted.current) {
9+
mounted.current = true;
10+
return callback();
11+
}
12+
}, []);
13+
};

src/hooks/use-did-update/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-did-update.hook";

src/hooks/use-did-update.hook.ts renamed to src/hooks/use-did-update/use-did-update.hook.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import { useEffect, useRef } from "react";
33

44
export const useDidUpdate = (
5-
callback: () => void,
6-
dependencies: readonly unknown[],
5+
callback: VoidFunction | (() => VoidFunction),
6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7+
dependencies: any[],
78
useOnMount = false,
89
) => {
910
const mountRef = useRef(useOnMount);

src/hooks/use-force-update.hook.ts

-7
This file was deleted.

src/hooks/use-force-update/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-force-update.hook";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useCallback, useState } from "react";
2+
3+
export const useForceUpdate = () => {
4+
const [, rerender] = useState(0);
5+
6+
return useCallback(() => {
7+
rerender((prev) => prev + 1);
8+
}, []);
9+
};

src/hooks/use-is-mounted/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-is-mounted.hook";

src/hooks/use-is-mounted.hook.ts renamed to src/hooks/use-is-mounted/use-is-mounted.hook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export const useIsMounted = () => {
88
componentIsMounted.current = false;
99
};
1010
}, []);
11-
return componentIsMounted.current;
11+
return componentIsMounted;
1212
};

src/hooks/use-isomorphic-effect.hook.ts

-7
This file was deleted.

src/hooks/use-layout-mount/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-layout-mount.hook";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable react-hooks/exhaustive-deps */
2+
import { useLayoutEffect, useRef } from "react";
3+
4+
export const useLayoutMount = (callback: VoidFunction | (() => VoidFunction)) => {
5+
const mounted = useRef(false);
6+
7+
useLayoutEffect(() => {
8+
if (!mounted.current) {
9+
mounted.current = true;
10+
return callback();
11+
}
12+
}, []);
13+
};

src/hooks/use-layout-update/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-layout-update.hook";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable react-hooks/exhaustive-deps */
2+
import { useLayoutEffect, useRef } from "react";
3+
4+
export const useLayoutUpdate = (
5+
callback: VoidFunction | (() => VoidFunction),
6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7+
dependencies: any[],
8+
useOnMount = false,
9+
) => {
10+
const mountRef = useRef(useOnMount);
11+
12+
useLayoutEffect(() => {
13+
if (!mountRef.current) {
14+
mountRef.current = true;
15+
return;
16+
}
17+
18+
return callback();
19+
}, dependencies);
20+
};

src/hooks/use-will-mount.hook.ts

-5
This file was deleted.

src/hooks/use-will-mount/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-will-mount.hook";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useRef } from "react";
2+
3+
export const useWillMount = (callback: VoidFunction) => {
4+
const willMount = useRef(true);
5+
6+
if (willMount.current) {
7+
callback();
8+
}
9+
10+
willMount.current = false;
11+
};

src/hooks/use-will-unmount/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-will-unmount.hook";
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react-hooks/exhaustive-deps */
22
import { useEffect } from "react";
33

4-
export const useWillUnmount = (callback: () => void) => {
4+
export const useWillUnmount = (callback: VoidFunction) => {
55
useEffect(() => callback, []);
66
};

src/index.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
// export * from "./lib" // export library entry point
2-
3-
export * from "./hooks/use-force-update.hook";
4-
export * from "./hooks/use-will-mount.hook";
5-
export * from "./hooks/use-did-mount.hook";
6-
export * from "./hooks/use-did-change.hook";
7-
export * from "./hooks/use-did-update.hook";
8-
export * from "./hooks/use-will-unmount.hook";
9-
export * from "./hooks/use-is-mounted.hook";
10-
export * from "./hooks/use-isomorphic-effect.hook";
1+
export * from "./hooks";

0 commit comments

Comments
 (0)