reactjs - react-select:在onChange期间从另一个Select清除所选值
问题描述
我的反应功能组件中有 2 个选择元素,如下所示:
<Select
options={areaTimeSlots}
onChange={ (selectedTimeSlotLabel) => handleTimeSlot (selectedTimeSlotLabel) }
placeholder="Select a delivery slot"
/>
和
<Select options={areaData} onChange={(value) => handleSelectedArea(value)} />
onChange
如果从 select-2 (handleSelectedArea) 触发,我想从 areaTimeSlots (select-1) 中清除所选选项。
我尝试使用反应钩子和 ref 如下所示,但两者都不起作用
const [selectedTimeSlotLabel, setTimeSlotLabel] = useState(null);
const handleSelectedArea = async (e: any) => {
setTimeSlotLabel(null);
}
<Select
options={areaTimeSlots}
isClearable={true}
onChange={ (selectedTimeSlotLabel) => handleTimeSlot (selectedTimeSlotLabel) }
value={selectedTimeSlotLabel} placeholder="Select a delivery slot"
/>
解决方案
推荐阅读
- c - 如何在阻止读取时检测 USB 断开连接?
- salesforce - 如何连接多个字段中存在的值并将其显示为目标字段中的单个值
- javascript - 将链接标记转换为链接
- unity3d - Unity 2D - 动画大幅降低 FPS
- php - 在 Woocommerce 中完成订单状态后保留自定义用户角色
- php - 连接 MySQL 失败:服务器向客户端发送未知字符集。请向开发人员报告 - SamplePage.php
- javascript - TypeScript 中最初未定义的变量的正确类型是什么?
- node.js - Swagger-ui 2.0 路径没有从顶部获得承载授权
- javascript - 当我包含完美的滚动条时,导航抽屉在短时间内可见
- javascript - 有没有办法在 NUXT/Vue 中获取 URL 中的最后一位数字