I've made a component that has a select option from Ionic/React where I have an object called licenseValue
. However, when I try to setLicenseValue
, if I try to console
the licenseValue
"value", it doesn't update the value.
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>
I'm using React / Ionic / hooks
question from:
https://stackoverflow.com/questions/65644969/react-ionic-hooks-component-setvalue-isnt-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…