reactjs - 从 React 的菜单项中的 onclick 事件更新状态
问题描述
每次单击新菜单项时,我都会尝试更新页面视图。我从数据库中提取这些菜单项并将它们映射并在下拉菜单中列出它们。
class AminoAcids extends Component {
componentDidMount() {
this.props.fetchMicros();
}
renderData() {
const { aminos } = this.props;
return aminos.map((micro, index) => {
return (
<option onClick={() =>
this.props.updateActiveResultView('aminoResults')} value={micro.value}
key={index}>{micro.name}</option>
)
})
}
render() {
return (
<select value={this.props.value} onChange={this.handleChange}>
<option value="" selected>--Amino Acids--</option>
{this.props.aminos && this.renderData()}
</select>
)
}
我的视图是 Intro、Amino 和 Antioxidants,现在它在我的减速器中设置在 Intro 上,所以我试图让它破坏 Intro 并在单击下拉菜单项之一时切换到 Amino。
减速机
const activeResultView = (state = 'Intro', action) => {
switch (action.type) {
case 'UPDATE_RESULT_VIEW':
return action.view;
default:
return state;
}
};
行动
export const updateActiveResultView = view => ({
type: 'UPDATE_RESULT_VIEW',
view,
});
我试着把它放在上面,<select>
但它给了我一个错误。现在它什么也没做。
解决方案
推荐阅读
- reactjs - 当更改来自另一个组件时,如何让 useEffect 仅更新更改
- regex - 从符号“X”之后的文本中提取数字
- c++ - 删除了复制构造函数的类仍然可以复制吗?
- javascript - 如何以天为单位获取 JS 中的日期差异(不考虑小时差异)
- c# - 在 Query 上用另一个模型初始化模型
- cypress - 使用 cypress 在浏览器选项卡上测试静音控制
- sas - 专注于“结果查看器”的快捷键
- json - NVD3:是否可以将输入数据和配置作为 JSON ,绘制堆叠的多轴图并绘制三角形图?
- java - 如何在多个数据中心的微服务项目中实现高 TPS?
- asp.net - 尝试初始化 Azure AD 时出现 404 未找到错误