reactjs - 使用 React 根据下拉值显示/隐藏文本字段
问题描述
我正在尝试TestField
根据下拉列表中选择的值显示/隐藏文本框的可见性(在我的代码中为 )。
I have seen several examples where conditional logic is written inside onChange
block but in my case I have to dispatch another action inside onChange
whenever a dropdown option is chosen and therefore don´t know how to add a conditional logic.
到目前为止,这是我的代码:
<InputGroup className='courses'>
<Dropdown className = "course"
items={["Mathematics", "Geography", "Social Sciences"]}
onChange={(selectedItem: DropdownItem | null): void =>
dispatch({
type: "getCourse",
index: i,
value: selectedItem?.value
})
}
/>
<TextField className=hours"
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
dispatch({
type: "getHours",
index: i,
value: e.target.value,
})
}
/>
</InputGroup>
我对 React 很陌生,想知道您是否可以指导我在代码中添加条件逻辑的位置。提前致谢。
解决方案
推荐阅读
- reactjs - setState 设置的变量在键盘处理程序事件中不可见
- bash - 有没有办法找到在特定时间创建的所有文件?
- javascript - 手机轮播bug
- system-verilog - SystemVerilog 中的符号“::*”是什么意思?
- asp.net - 故障组合在 Facebook Api v 7.0 中不起作用
- python - 使用 pygame 时没有弹出窗口
- python - 如何创建 Tkinter 背景图像
- php - 将 wordpress 迁移到新的 Windows 2016 - 出现 HTTP 错误 500.0
- html - 如何在另一个元素内对齐 SVG(例如锚点)
- java - 在 Windows 10 中使用 Java 构建文件索引