Skip to content

Commit e5f96cf

Browse files
EmilyyyLiu刘欢
andauthored
refactor: Upgrade utils and replace useMergedState (#74)
* refactor: Upgrade utils and replace useMergedState * feat: word * feat: default mergedValue * feat: delete internalValue --------- Co-authored-by: 刘欢 <lh01217311@antgroup.com>
1 parent f9318ce commit e5f96cf

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"classnames": "^2.2.1",
4747
"@rc-component/input": "~1.1.0",
4848
"@rc-component/resize-observer": "^1.0.0",
49-
"@rc-component/util": "^1.2.0"
49+
"@rc-component/util": "^1.3.0"
5050
},
5151
"devDependencies": {
5252
"@rc-component/father-plugin": "^2.0.2",

src/ResizableTextArea.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ResizeObserver from '@rc-component/resize-observer';
2+
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
23
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
3-
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
44
import raf from '@rc-component/util/lib/raf';
55
import classNames from 'classnames';
66
import * as React from 'react';
@@ -37,10 +37,11 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
3737
};
3838

3939
// =============================== Value ================================
40-
const [mergedValue, setMergedValue] = useMergedState(defaultValue, {
40+
const [internalValue, setMergedValue] = useControlledState(
41+
defaultValue,
4142
value,
42-
postState: (val) => val ?? '',
43-
});
43+
);
44+
const mergedValue = internalValue ?? '';
4445

4546
const onInternalChange: React.ChangeEventHandler<HTMLTextAreaElement> = (
4647
event,

src/TextArea.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import clsx from 'classnames';
21
import { BaseInput } from '@rc-component/input';
32
import { type HolderRef } from '@rc-component/input/lib/BaseInput';
43
import useCount from '@rc-component/input/lib/hooks/useCount';
54
import { resolveOnChange } from '@rc-component/input/lib/utils/commonUtils';
6-
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
5+
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
6+
import clsx from 'classnames';
77
import type { ReactNode } from 'react';
88
import React, { useEffect, useImperativeHandle, useRef } from 'react';
99
import ResizableTextArea from './ResizableTextArea';
@@ -45,10 +45,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
4545
},
4646
ref,
4747
) => {
48-
const [value, setValue] = useMergedState(defaultValue, {
49-
value: customValue,
50-
defaultValue,
51-
});
48+
const [value, setValue] = useControlledState(defaultValue, customValue);
5249
const formatValue =
5350
value === undefined || value === null ? '' : String(value);
5451

0 commit comments

Comments
 (0)