diff --git a/packages/react/src/hooks/index.ts b/packages/react/src/hooks/index.ts index 5e354cd50..a4c75d50a 100644 --- a/packages/react/src/hooks/index.ts +++ b/packages/react/src/hooks/index.ts @@ -1,5 +1,5 @@ +export { useIsCSROnly } from './useIsCSROnly' export { useIsChanged } from './useIsChanged' -export { useIsMounted } from './useIsMounted' export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect' export { useKey } from './useKey' export { usePrevious } from './usePrevious' diff --git a/packages/react/src/hooks/useIsCSROnly.spec.ts b/packages/react/src/hooks/useIsCSROnly.spec.ts new file mode 100644 index 000000000..edb9d9f82 --- /dev/null +++ b/packages/react/src/hooks/useIsCSROnly.spec.ts @@ -0,0 +1,12 @@ +import { renderHook } from '@testing-library/react' +import { useIsCSROnly } from '.' + +describe('useIsCSROnly', () => { + it('should return true when client side painting start', () => { + const { + result: { current: isClient }, + } = renderHook(() => useIsCSROnly()) + + expect(isClient).toBe(true) + }) +}) diff --git a/packages/react/src/hooks/useIsCSROnly.ts b/packages/react/src/hooks/useIsCSROnly.ts new file mode 100644 index 000000000..a23bb2e7c --- /dev/null +++ b/packages/react/src/hooks/useIsCSROnly.ts @@ -0,0 +1,12 @@ +import { useState } from 'react' +import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect' + +export const useIsCSROnly = () => { + const [isClient, setIsClient] = useState(false) + + useIsomorphicLayoutEffect(() => { + setIsClient(true) + }, []) + + return isClient +} diff --git a/packages/react/src/hooks/useIsMounted.spec.ts b/packages/react/src/hooks/useIsMounted.spec.ts deleted file mode 100644 index 5954eaacb..000000000 --- a/packages/react/src/hooks/useIsMounted.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { renderHook } from '@testing-library/react' -import { useIsMounted } from '.' - -describe('useIsMounted', () => { - it('should return true when component is mounted', () => { - const { - result: { current: isMounted }, - } = renderHook(() => useIsMounted()) - - expect(isMounted).toBe(true) - }) -}) diff --git a/packages/react/src/hooks/useIsMounted.ts b/packages/react/src/hooks/useIsMounted.ts deleted file mode 100644 index 3ce612fe5..000000000 --- a/packages/react/src/hooks/useIsMounted.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useEffect, useState } from 'react' - -export const useIsMounted = () => { - const [isMounted, setIsMounted] = useState(false) - - useEffect(() => { - setIsMounted(true) - }, []) - - return isMounted -}