Skip to content

Commit

Permalink
feat: 🎸 Major update
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 🧨 structure and hooks names changes
  • Loading branch information
prc5 committed Oct 18, 2024
1 parent 64e563d commit 743eea9
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 41 deletions.
9 changes: 9 additions & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export * from "./use-deps-change";
export * from "./use-did-mount";
export * from "./use-did-update";
export * from "./use-force-update";
export * from "./use-is-mounted";
export * from "./use-layout-mount";
export * from "./use-layout-update";
export * from "./use-will-mount";
export * from "./use-will-unmount";
1 change: 1 addition & 0 deletions src/hooks/use-deps-change/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-deps-change.hook";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from "react";

export const useDidChange = <T extends unknown[]>(
callback: (previousDependencies: T | null) => void,
export const useDepsChange = <T extends any[]>(
callback: VoidFunction | ((previousDependencies: T | null) => VoidFunction),
dependencies: T,
useOnMount = false,
) => {
Expand Down
6 changes: 0 additions & 6 deletions src/hooks/use-did-mount.hook.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/hooks/use-did-mount/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-did-mount.hook";
13 changes: 13 additions & 0 deletions src/hooks/use-did-mount/use-did-mount.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect, useRef } from "react";

export const useDidMount = (callback: VoidFunction | (() => VoidFunction)) => {
const mounted = useRef(false);

useEffect(() => {
if (!mounted.current) {
mounted.current = true;
return callback();
}
}, []);
};
1 change: 1 addition & 0 deletions src/hooks/use-did-update/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-did-update.hook";
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { useEffect, useRef } from "react";

export const useDidUpdate = (
callback: () => void,
dependencies: readonly unknown[],
callback: VoidFunction | (() => VoidFunction),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dependencies: any[],
useOnMount = false,
) => {
const mountRef = useRef(useOnMount);
Expand Down
7 changes: 0 additions & 7 deletions src/hooks/use-force-update.hook.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/hooks/use-force-update/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-force-update.hook";
9 changes: 9 additions & 0 deletions src/hooks/use-force-update/use-force-update.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useCallback, useState } from "react";

export const useForceUpdate = () => {
const [, rerender] = useState(0);

return useCallback(() => {
rerender((prev) => prev + 1);
}, []);
};
1 change: 1 addition & 0 deletions src/hooks/use-is-mounted/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-is-mounted.hook";
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const useIsMounted = () => {
componentIsMounted.current = false;
};
}, []);
return componentIsMounted.current;
return componentIsMounted;
};
7 changes: 0 additions & 7 deletions src/hooks/use-isomorphic-effect.hook.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/hooks/use-layout-mount/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-layout-mount.hook";
13 changes: 13 additions & 0 deletions src/hooks/use-layout-mount/use-layout-mount.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useLayoutEffect, useRef } from "react";

export const useLayoutMount = (callback: VoidFunction | (() => VoidFunction)) => {
const mounted = useRef(false);

useLayoutEffect(() => {
if (!mounted.current) {
mounted.current = true;
return callback();
}
}, []);
};
1 change: 1 addition & 0 deletions src/hooks/use-layout-update/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-layout-update.hook";
20 changes: 20 additions & 0 deletions src/hooks/use-layout-update/use-layout-update.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useLayoutEffect, useRef } from "react";

export const useLayoutUpdate = (
callback: VoidFunction | (() => VoidFunction),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dependencies: any[],
useOnMount = false,
) => {
const mountRef = useRef(useOnMount);

useLayoutEffect(() => {
if (!mountRef.current) {
mountRef.current = true;
return;
}

return callback();
}, dependencies);
};
5 changes: 0 additions & 5 deletions src/hooks/use-will-mount.hook.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/hooks/use-will-mount/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-will-mount.hook";
11 changes: 11 additions & 0 deletions src/hooks/use-will-mount/use-will-mount.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useRef } from "react";

export const useWillMount = (callback: VoidFunction) => {
const willMount = useRef(true);

if (willMount.current) {
callback();
}

willMount.current = false;
};
1 change: 1 addition & 0 deletions src/hooks/use-will-unmount/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-will-unmount.hook";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect } from "react";

export const useWillUnmount = (callback: () => void) => {
export const useWillUnmount = (callback: VoidFunction) => {
useEffect(() => callback, []);
};
11 changes: 1 addition & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
// export * from "./lib" // export library entry point

export * from "./hooks/use-force-update.hook";
export * from "./hooks/use-will-mount.hook";
export * from "./hooks/use-did-mount.hook";
export * from "./hooks/use-did-change.hook";
export * from "./hooks/use-did-update.hook";
export * from "./hooks/use-will-unmount.hook";
export * from "./hooks/use-is-mounted.hook";
export * from "./hooks/use-isomorphic-effect.hook";
export * from "./hooks";

0 comments on commit 743eea9

Please sign in to comment.