javascript - react js:TypeError:object null is not iterable(无法读取属性Symbol(Symbol.iterator))
问题描述
this.state.hiring.map(h => (
<FormApp
condType={h.type}
condRef={h.ref}
label={h.name}
labelName={h.name}
name={h.id}
id={h.name}
validations={h.required == true ? [this.required] : null}
dataList={this.state[h.ref]}
onChange={this.onChangeInput}
/>
));
我想要
if (h.requered == true) { return [this.required] } else { null }
我有问题
react js:TypeError:object null is not iterable(无法读取属性Symbol(Symbol.iterator))
解决方案
也许你可以像这样修改你的代码:
const { hiring } = this.state;
hiring instanceof Array && hiring.map(h => { // ==> Validate hiring before use it.
if (h.requered == true) {
return (
<FormApp
condType={h.type}
condRef={h.ref}
label={h.name}
labelName={h.name}
name={h.id}
id={h.name}
validations={h.required == true ? [this.required] : null}
dataList={this.state[h.ref]}
onChange={this.onChangeInput}
/>
);
} else {
return null;
}
});
推荐阅读
- android - ContactsContract.CommonDataKinds.Event.START_DATE 包括联系电话号码
- javascript - 我无法将不同的模态窗口与不同的对象相关联
- userform - 我有一个准备就绪的用户表单,但是当我尝试将其添加为加载项时,它不起作用。请帮忙!显示的错误是下标超出范围
- http - 为什么不推荐使用 HAL(超文本应用程序语言)并且不广泛使用?
- python-3.x - 如何去除图像的背景
- python-3.7 - 我有 python 3.9,我想用 python 3.7 创建虚拟环境
- java - 如何添加手指移动 Java 画布
- java - 我怎样才能只用一种方法制作这个计算器?
- ios - 使用 UIView 的框架裁剪 CVPixelBuffer
- php - 订单完成后,WooCommerce 将文件从服务器下载到客户端浏览器