【发布时间】:2021-04-15 02:29:10
【问题描述】:
我制作了一个组件,该组件具有来自 Ionic/React 的选择选项,其中我有一个名为 licenseValue 的对象。但是,当我尝试setLicenseValue 时,如果我尝试console licenseValue“值”,它不会更新该值。
import licenseValuesArray from './somewhere'
const [licenseValues, setLicenseValues] = useState(licenseValuesArray);
useEffect(() => {
setLicenseValues(licenseValuesArray);
}, [licenseValuesArray]);
const [licenseValue, setLicenseValue] = useState(0);
<IonSelect
value="value"
okText="Okay"
cancelText="Dismiss"
onIonChange={(e) => {
e.preventDefault();
let a = e.detail.value;
setLicenseValue(a);
console.log(a, "defina periodo");//retrieve the "a" value
console.log(licenseValue, "defina periodo");//doesnt retrieve the value from setLicenseValue
}}
>
{licenseValues.map((item) => (
<IonSelectOption key={item.title} value={item}>
{item.title}
</IonSelectOption>
))}
</IonSelect>
我正在使用 React / Ionic / hooks
【问题讨论】:
标签: reactjs ionic-framework react-hooks