-
-
Notifications
You must be signed in to change notification settings - Fork 478
refactor: Upgrade utils and replace useMergedState #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import type { AlignType, BuildInPlacements } from '@rc-component/trigger/lib/interface'; | ||
import cls from 'classnames'; | ||
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; | ||
import useMergedState from '@rc-component/util/lib/hooks/useMergedState'; | ||
import useControlledState from '@rc-component/util/lib/hooks/useControlledState'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import isMobile from '@rc-component/util/lib/isMobile'; | ||
import { useComposeRef } from '@rc-component/util/lib/ref'; | ||
import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode'; | ||
|
@@ -383,10 +383,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref) | |
setRendered(true); | ||
}, []); | ||
|
||
const [innerOpen, setInnerOpen] = useMergedState<boolean>(false, { | ||
defaultValue: defaultOpen, | ||
value: open, | ||
}); | ||
const [innerOpen, setInnerOpen] = useControlledState<boolean>(defaultOpen || false, open); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在原本 useMergedState 的使用中 defaultOpen 的使用优先于默认的 false |
||
|
||
let mergedOpen = rendered ? innerOpen : false; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
* - `combobox` mode not support `optionLabelProp` | ||
*/ | ||
|
||
import useMergedState from '@rc-component/util/lib/hooks/useMergedState'; | ||
import useControlledState from '@rc-component/util/lib/hooks/useControlledState'; | ||
EmilyyyLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import warning from '@rc-component/util/lib/warning'; | ||
import * as React from 'react'; | ||
import type { | ||
|
@@ -272,10 +272,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp | |
); | ||
|
||
// =========================== Search =========================== | ||
const [mergedSearchValue, setSearchValue] = useMergedState('', { | ||
value: searchValue, | ||
postState: (search) => search || '', | ||
}); | ||
const [mergedSearchValue, setSearchValue] = useControlledState('', searchValue); | ||
|
||
|
||
// =========================== Option =========================== | ||
const parsedOptions = useOptions( | ||
|
@@ -343,9 +340,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp | |
); | ||
|
||
// =========================== Values =========================== | ||
const [internalValue, setInternalValue] = useMergedState(defaultValue, { | ||
value, | ||
}); | ||
const [internalValue, setInternalValue] = useControlledState(defaultValue, value); | ||
EmilyyyLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Merged value with LabelValueType | ||
const rawLabeledValues = React.useMemo(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to upgrade to the latest version of
@rc-component/util
. However, ensure that all the changes in the new version are compatible with the current implementation and that all functionalities are working as expected.