fix: fix bug about updating parent component value in CountryCodeSelect (#1891)

This commit is contained in:
Yaodong Yu 2023-05-25 10:45:13 +08:00 committed by GitHub
parent d29fc88d68
commit 80e6e7f0a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,12 @@ import React from "react";
export const CountryCodeSelect = (props) => { export const CountryCodeSelect = (props) => {
const {onChange, style, disabled} = props; const {onChange, style, disabled} = props;
const countryCodes = props.countryCodes ?? []; const countryCodes = props.countryCodes ?? [];
const [value, setValue] = React.useState(countryCodes.length > 0 ? countryCodes[0] : ""); const [value, setValue] = React.useState("");
React.useEffect(() => {
const initValue = countryCodes.length > 0 ? countryCodes[0] : "";
handleOnChange(initValue);
}, []);
const handleOnChange = (value) => { const handleOnChange = (value) => {
setValue(value); setValue(value);