Skip to content

Commit 75ab148

Browse files
wo-o29kimyouknow
andauthored
refactor(usePrevious): remove undefined from compare argument and return type (#272)
Co-authored-by: kimyouknow <kimyouknow@toss.im> Co-authored-by: 김윤호 yunho <kimyouknow@naver.com>
1 parent 498e677 commit 75ab148

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-simplikit': patch
3+
---
4+
5+
refactor(usePrevious): remove unnecessary `undefined` from compare argument and return type

packages/core/src/hooks/usePrevious/ko/usePrevious.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
## 인터페이스
66

77
```ts
8-
function usePrevious<T>(
9-
state: T,
10-
compare: (prev: T | undefined, next: T) => boolean
11-
): T | undefined;
8+
function usePrevious<T>(state: T, compare: (prev: T, next: T) => boolean): T;
129
```
1310

1411
### 파라미터
@@ -22,15 +19,15 @@ function usePrevious<T>(
2219

2320
<Interface
2421
name="compare"
25-
type="(prev: T | undefined, next: T) => boolean"
22+
type="(prev: T, next: T) => boolean"
2623
description="상태가 변경되었는지를 판단하기 위한 선택적 비교 함수예요."
2724
/>
2825

2926
### 반환 값
3027

3128
<Interface
3229
name=""
33-
type="T | undefined"
30+
type="T"
3431
description="상태의 이전 값이에요."
3532
/>
3633

packages/core/src/hooks/usePrevious/usePrevious.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
## Interface
66

77
```ts
8-
function usePrevious<T>(
9-
state: T,
10-
compare: (prev: T | undefined, next: T) => boolean
11-
): T | undefined;
8+
function usePrevious<T>(state: T, compare: (prev: T, next: T) => boolean): T;
129
```
1310

1411
### Parameters
@@ -22,15 +19,15 @@ function usePrevious<T>(
2219

2320
<Interface
2421
name="compare"
25-
type="(prev: T | undefined, next: T) => boolean"
22+
type="(prev: T, next: T) => boolean"
2623
description="An optional comparison function to determine if the state has changed."
2724
/>
2825

2926
### Return Value
3027

3128
<Interface
3229
name=""
33-
type="T | undefined"
30+
type="T"
3431
description="previous value of the state."
3532
/>
3633

packages/core/src/hooks/usePrevious/usePrevious.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef } from 'react';
22

3-
const strictEquals = <T>(prev: T | undefined, next: T) => prev === next;
3+
const strictEquals = <T>(prev: T, next: T) => prev === next;
44

55
/**
66
* @description
@@ -11,9 +11,9 @@ const strictEquals = <T>(prev: T | undefined, next: T) => prev === next;
1111
*
1212
* @template T - The type of the state.
1313
* @param {T} state - The state whose previous value is to be tracked.
14-
* @param {(prev: T | undefined, next: T) => boolean} [compare] - An optional comparison function to determine if the state has changed.
14+
* @param {(prev: T, next: T) => boolean} [compare] - An optional comparison function to determine if the state has changed.
1515
*
16-
* @returns {T | undefined} The previous value of the state.
16+
* @returns {T} The previous value of the state.
1717
*
1818
* @example
1919
* const [count, setCount] = useState(0);

0 commit comments

Comments
 (0)