@codeleap/hooks 5.5.4 → 5.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/hooks",
3
- "version": "5.5.4",
3
+ "version": "5.6.3",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -9,19 +9,19 @@
9
9
  "directory": "packages/hooks"
10
10
  },
11
11
  "devDependencies": {
12
- "@codeleap/config": "5.5.4",
13
- "@codeleap/types": "5.5.4",
14
- "@codeleap/utils": "5.5.4",
15
- "@codeleap/logger": "5.5.4",
12
+ "@codeleap/config": "5.6.3",
13
+ "@codeleap/types": "5.6.3",
14
+ "@codeleap/utils": "5.6.3",
15
+ "@codeleap/logger": "5.6.3",
16
16
  "ts-node-dev": "1.1.8"
17
17
  },
18
18
  "scripts": {
19
19
  "build": "echo 'No build needed'"
20
20
  },
21
21
  "peerDependencies": {
22
- "@codeleap/types": "5.5.4",
23
- "@codeleap/utils": "5.5.4",
24
- "@codeleap/logger": "5.5.4",
22
+ "@codeleap/types": "5.6.3",
23
+ "@codeleap/utils": "5.6.3",
24
+ "@codeleap/logger": "5.6.3",
25
25
  "axios": "^1.7.9",
26
26
  "typescript": "5.5.2",
27
27
  "react": "18.2.0",
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/hooks",
3
- "version": "5.5.4",
3
+ "version": "5.6.3",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -31,7 +31,7 @@ export * from './useEffectOnce'
31
31
  export * from './useUnmount'
32
32
  export * from './useSearch'
33
33
  export * from './usePartialState'
34
- export * from './useIsClient'
34
+ export * from './useIsMounted'
35
35
  export * from './useComponentTestId'
36
36
  export * from './useId'
37
37
 
@@ -0,0 +1,31 @@
1
+ import { useEffect, useLayoutEffect, useState } from 'react'
2
+
3
+ const isReactNativeOrServer = typeof navigator !== 'undefined'
4
+
5
+ const useIsomorphicLayoutEffect =
6
+ isReactNativeOrServer ? useLayoutEffect : useEffect
7
+
8
+ /**
9
+ * Hook to check if the component has mounted. SSR safe.
10
+ * @return true after the component's html is mounted in the browser.
11
+ */
12
+ export function useIsMounted() {
13
+ const [mounted, setMounted] = useState(false)
14
+
15
+ useIsomorphicLayoutEffect(() => {
16
+ setMounted(true)
17
+ }, [])
18
+
19
+ return mounted
20
+ }
21
+
22
+ /**
23
+ * Hook to check if the code is running on the client-side.
24
+ * NOTE: This is just a mirror of `useIsMounted` for retrocompatibility reasons
25
+ * @return `isClient: true` after the component is mounted in the browser.
26
+ */
27
+ export function useIsClient() {
28
+ return {
29
+ isClient: useIsMounted(),
30
+ }
31
+ }
@@ -1,17 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
-
3
- /**
4
- * Hook to check if the code is running on the client-side.
5
- * @return `isClient: true` after the component is mounted in the browser.
6
- */
7
- export function useIsClient() {
8
- const [isClient, setIsClient] = useState(false)
9
-
10
- useEffect(() => {
11
- setIsClient(true)
12
- }, [])
13
-
14
- return {
15
- isClient
16
- }
17
- }