reactjs - 使用 useState 时状态更新延迟在选择列表内
问题描述
我宣布useState<ICurrency>
为
const [hwSalesPriceCurrency, setHwSalesPriceCurrency] = useState<ICurrency>();
有一个 html,其中我有一个选择列表作为
<label>
Price Currency12:<span className="redStar">*</span>
</label>
<Select
type="input-single"
placeholder="Select Currency"
disabled={false}
label={
uscCurrencyEdit !== ""
? uscCurrencyEdit
: hwSalesPriceCurrency
? hwSalesPriceCurrency.unit
: ""
}
items={currencies.map(v => ({ title: v.unit, value: v }))}
onChange={({ value }: { value: ICurrency }) => {
console.log("onChange value::");
console.log(value);
setHwSalesPriceCurrency(value);
uscCurrencyChanged(value.unit);
pricingTotal();
}}
/>
当我选择不同的值时, onChange 会被触发。我看到 onChange 中的值是我选择的最新值,但setHwSalesPriceCurrency(value)
没有将状态更新为最新值。它将其更新为以前的值。它旁边还有另一个文本框,它与此选择列表无关,但是在将一些数字输入文本框后,值会更新。
有没有什么方法可以让状态更新立即更新,而无需在另一个文本框中输入一些数字?
解决方案
推荐阅读
- javascript - 使用 Javascript 变量作为 EJS 数组的索引 - NODEJS
- javascript - 无法访问 php 中发布的数据
- python - 如何让 python scapy 从命名的 fifo 中嗅探
- java - Interbase DB JDBC 连接
- angular - 我不断收到错误消息:错误:提供给 Query.startAt() 的参数过多。使用 AngularFire2 时
- spring-boot - 在spring security(Spring boot)中获取所有url中的禁止错误
- neo4j - 两组节点之间的最短路径
- java - 如何在我的 Spring 应用程序中获取 Firebase 的 Oauth 2.0 访问令牌
- rhel6 - 我可以在 RHEL6 下的 SystemTap 中获取当前工作目录吗
- python - 在指定距离/边界内获取点标签 - Python