Skip to content

Commit 1add323

Browse files
authored
Fix initial value not being set on dropdown picker (#828)
1 parent 3b95724 commit 1add323

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/core/src/components/Picker/dropdown/DropDownPicker.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import PickerInputContainer from "../PickerInputContainer";
1515
import DropDownPickerComponent from "react-native-dropdown-picker";
1616
import { withTheme } from "../../../theming";
1717
import PickerItem, { PickerItemProps } from "./PickerItem";
18+
import { useOnUpdate } from "../../../hooks";
1819

1920
const DropDownPicker: React.FC<
2021
React.PropsWithChildren<
@@ -42,8 +43,8 @@ const DropDownPicker: React.FC<
4243
}) => {
4344
const [pickerVisible, setPickerVisible] = React.useState(false);
4445
const [internalValue, setInternalValue] = React.useState<
45-
string | number | (string | number)[]
46-
>();
46+
string | number | (string | number)[] | undefined
47+
>(value);
4748

4849
const isMultiSelect = Array.isArray(value);
4950

@@ -70,12 +71,11 @@ const DropDownPicker: React.FC<
7071
[optionsProp]
7172
);
7273

73-
React.useEffect(() => {
74+
useOnUpdate(() => {
7475
onValueChange?.(
7576
(isMultiSelect ? internalValue ?? [] : internalValue ?? "") as any // cannot determine if multiselect or not on compile time
7677
);
7778
// onValueChange excluded to prevent running on every re-render when using an anoymous function, which is the common case
78-
// eslint-disable-next-line react-hooks/exhaustive-deps
7979
}, [internalValue]);
8080

8181
React.useEffect(() => {

0 commit comments

Comments
 (0)