Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-simplikit",
"version": "0.0.40",
"version": "0.1.0",
"main": "./src/index.ts",
"type": "module",
"sideEffects": false,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useClientLayoutEffect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useClientLayoutEffect } from './useClientLayoutEffect.ts';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# useIsomorphicLayoutEffect
# useClientLayoutEffect

SSR 환경에서는 DOM에 대한 접근이 불가하기 때문에 useLayoutEffect 훅 사용 시 경고가 발생해요. 이 훅은 브라우저에서 SSR 경고를 트리거하지 않고 useLayoutEffect의 동작을 제공해요. DOM 업데이트 후 페인트 전에 동기적으로 실행되며, 다음과 같은 상황에서 효과적으로 사용할 수 있어요:

Expand All @@ -10,7 +10,7 @@ SSR 환경에서는 DOM에 대한 접근이 불가하기 때문에 useLayoutEffe
## 인터페이스

```ts
function useIsomorphicLayoutEffect(
function useClientLayoutEffect(
effect: React.EffectCallback,
deps: React.DependencyList
): void;
Expand Down Expand Up @@ -38,7 +38,7 @@ function useIsomorphicLayoutEffect(
## 예시

```tsx
useIsomorphicLayoutEffect(() => {
useClientLayoutEffect(() => {
// 클라이언트 측의 레이아웃 단계에서 실행될 코드
}, [dep1, dep2, ...]);
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# useIsomorphicLayoutEffect
# useClientLayoutEffect

`useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering. During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.
`useClientLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering. During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.

This hook runs synchronously after DOM updates but before paint, making it ideal for:

Expand All @@ -12,7 +12,7 @@ This hook runs synchronously after DOM updates but before paint, making it ideal
## Interface

```ts
function useIsomorphicLayoutEffect(
function useClientLayoutEffect(
effect: React.EffectCallback,
deps: React.DependencyList
): void;
Expand Down Expand Up @@ -40,7 +40,7 @@ This hook does not return anything.
## Example

```tsx
useIsomorphicLayoutEffect(() => {
useClientLayoutEffect(() => {
// Code to be executed during the layout phase on the client side
}, [dep1, dep2, ...]);
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

describe('useIsomorphicLayoutEffect', () => {
describe('useClientLayoutEffect', () => {
const originalWindow = global.window;

beforeEach(() => {
Expand All @@ -11,20 +11,20 @@ describe('useIsomorphicLayoutEffect', () => {
global.window = undefined as unknown as Window & typeof globalThis;

const { useEffect, useLayoutEffect } = await import('react');
const { useIsomorphicLayoutEffect } = await import('./useIsomorphicLayoutEffect.ts');
const { useClientLayoutEffect } = await import('./useClientLayoutEffect.ts');

expect(useIsomorphicLayoutEffect).toBe(useEffect);
expect(useIsomorphicLayoutEffect).not.toBe(useLayoutEffect);
expect(useClientLayoutEffect).toBe(useEffect);
expect(useClientLayoutEffect).not.toBe(useLayoutEffect);
});

it('should use useLayoutEffect on client side', async () => {
global.window = originalWindow;

const { useEffect, useLayoutEffect } = await import('react');
const { useIsomorphicLayoutEffect } = await import('./useIsomorphicLayoutEffect.ts');
const { useClientLayoutEffect } = await import('./useClientLayoutEffect.ts');

expect(useIsomorphicLayoutEffect).toBe(useLayoutEffect);
expect(useIsomorphicLayoutEffect).not.toBe(useEffect);
expect(useClientLayoutEffect).toBe(useLayoutEffect);
expect(useClientLayoutEffect).not.toBe(useEffect);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const isServer = typeof window === 'undefined';

/**
* @description
* `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
* `useClientLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
* During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.
*
* This hook runs synchronously after DOM updates but before paint, making it ideal for:
Expand All @@ -18,8 +18,8 @@ const isServer = typeof window === 'undefined';
* @param {React.DependencyList} [deps] - An optional array of dependencies.
*
* @example
* useIsomorphicLayoutEffect(() => {
* useClientLayoutEffect(() => {
* // Code to be executed during the layout phase on the client side
* }, [dep1, dep2, ...]);
*/
export const useIsomorphicLayoutEffect = isServer ? useEffect : useLayoutEffect;
export const useClientLayoutEffect = isServer ? useEffect : useLayoutEffect;
1 change: 0 additions & 1 deletion src/hooks/useIsomorphicLayoutEffect/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { ImpressionArea } from './components/ImpressionArea/index.ts';

Check warning on line 1 in src/index.ts

View workflow job for this annotation

GitHub Actions / quality (lint)

Run autofix to sort these exports!
export { Separated } from './components/Separated/index.ts';
export { SwitchCase } from './components/SwitchCase/index.ts';
export { useAsyncEffect } from './hooks/useAsyncEffect/index.ts';
Expand All @@ -15,7 +15,7 @@
export { useInputState } from './hooks/useInputState/index.ts';
export { useIntersectionObserver } from './hooks/useIntersectionObserver/index.ts';
export { useInterval } from './hooks/useInterval/index.ts';
export { useIsomorphicLayoutEffect } from './hooks/useIsomorphicLayoutEffect/index.ts';
export { useClientLayoutEffect } from './hooks/useClientLayoutEffect/index.ts';
export { useLoading } from './hooks/useLoading/index.ts';
export { useLongPress } from './hooks/useLongPress/index.ts';
export { useMap } from './hooks/useMap/index.ts';
Expand Down
Loading