Skip to content

Commit 262823e

Browse files
committed
chore: rename
1 parent eca4dd1 commit 262823e

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Updater<T> = (updater: T | ((origin: T) => T)) => void;
88
* From React 18, we do not need safe `useState` since it will not throw for unmounted update.
99
* This hooks remove the `onChange` & `postState` logic since we only need basic merged state logic.
1010
*/
11-
export default function usePropState<T>(
11+
export default function useControlledState<T>(
1212
defaultStateValue: T | (() => T),
1313
value?: T,
1414
): [T, Updater<T>] {

src/hooks/useMergedState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function hasValue(value: any) {
1313
}
1414

1515
/**
16-
* @deprecated Please use `usePropState` instead if not need support < React 18.
16+
* @deprecated Please use `useControlledState` instead if not need support < React 18.
1717
* Similar to `useState` but will use props value if provided.
1818
* Note that internal use rc-util `useState` hook.
1919
*/

tests/hooks.test.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import useMergedState from '../src/hooks/useMergedState';
88
import useMobile from '../src/hooks/useMobile';
99
import useState from '../src/hooks/useState';
1010
import useSyncState from '../src/hooks/useSyncState';
11-
import usePropState from '../src/hooks/usePropState';
11+
import useControlledState from '../src/hooks/useControlledState';
1212

1313
global.disableUseId = false;
1414

@@ -318,13 +318,16 @@ describe('hooks', () => {
318318
});
319319
});
320320

321-
describe('usePropState', () => {
321+
describe('useControlledState', () => {
322322
const FC: React.FC<{
323323
value?: string;
324324
defaultValue?: string | (() => string);
325325
}> = props => {
326326
const { value, defaultValue } = props;
327-
const [val, setVal] = usePropState<string>(defaultValue ?? null, value);
327+
const [val, setVal] = useControlledState<string>(
328+
defaultValue ?? null,
329+
value,
330+
);
328331
return (
329332
<>
330333
<input
@@ -367,7 +370,7 @@ describe('hooks', () => {
367370
let renderTimes = 0;
368371

369372
const Test = () => {
370-
const [val, setVal] = usePropState(0);
373+
const [val, setVal] = useControlledState(0);
371374

372375
React.useEffect(() => {
373376
renderTimes += 1;
@@ -385,7 +388,7 @@ describe('hooks', () => {
385388

386389
it('React 18 should not reset to undefined', () => {
387390
const Demo = () => {
388-
const [val] = usePropState(33, undefined);
391+
const [val] = useControlledState(33, undefined);
389392

390393
return <div>{val}</div>;
391394
};
@@ -401,7 +404,7 @@ describe('hooks', () => {
401404

402405
it('uncontrolled to controlled', () => {
403406
const Demo: React.FC<Readonly<{ value?: number }>> = ({ value }) => {
404-
const [mergedValue, setMergedValue] = usePropState<number>(
407+
const [mergedValue, setMergedValue] = useControlledState<number>(
405408
() => 233,
406409
value,
407410
);
@@ -437,7 +440,7 @@ describe('hooks', () => {
437440

438441
it('should alway use option value', () => {
439442
const Test: React.FC<Readonly<{ value?: number }>> = ({ value }) => {
440-
const [mergedValue, setMergedValue] = usePropState<number>(
443+
const [mergedValue, setMergedValue] = useControlledState<number>(
441444
undefined,
442445
value,
443446
);
@@ -462,7 +465,7 @@ describe('hooks', () => {
462465
let count = 0;
463466

464467
const Demo: React.FC = () => {
465-
const [] = usePropState(undefined);
468+
const [] = useControlledState(undefined);
466469
count += 1;
467470
return null;
468471
};

0 commit comments

Comments
 (0)