@codeleap/hooks 5.5.4 → 5.6.2
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 +8 -8
- package/package.json.bak +1 -1
- package/src/index.ts +1 -1
- package/src/useIsMounted.ts +31 -0
- package/src/useIsClient.ts +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/hooks",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.2",
|
|
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.
|
|
13
|
-
"@codeleap/types": "5.
|
|
14
|
-
"@codeleap/utils": "5.
|
|
15
|
-
"@codeleap/logger": "5.
|
|
12
|
+
"@codeleap/config": "5.6.2",
|
|
13
|
+
"@codeleap/types": "5.6.2",
|
|
14
|
+
"@codeleap/utils": "5.6.2",
|
|
15
|
+
"@codeleap/logger": "5.6.2",
|
|
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.
|
|
23
|
-
"@codeleap/utils": "5.
|
|
24
|
-
"@codeleap/logger": "5.
|
|
22
|
+
"@codeleap/types": "5.6.2",
|
|
23
|
+
"@codeleap/utils": "5.6.2",
|
|
24
|
+
"@codeleap/logger": "5.6.2",
|
|
25
25
|
"axios": "^1.7.9",
|
|
26
26
|
"typescript": "5.5.2",
|
|
27
27
|
"react": "18.2.0",
|
package/package.json.bak
CHANGED
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 './
|
|
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
|
+
}
|
package/src/useIsClient.ts
DELETED
|
@@ -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
|
-
}
|