[英]react js : TypeError: object null is not iterable (cannot read property 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}
/>
));
I want to if (h.requered == true) { return [this.required] } else { null }
我想要if (h.requered == true) { return [this.required] } else { null }
I have problem 我有问题
react js : TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator)) 反应js: TypeError:对象null不可迭代(无法读取属性Symbol(Symbol.iterator))
Maybe you can modify your code like this: 也许您可以像这样修改您的代码:
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;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.