gpt4 book ai didi

javascript - react js : TypeError: object null is not iterable (cannot read property Symbol(Symbol.迭代器))

转载 作者:行者123 更新时间:2023-12-03 00:01:12 35 4
gpt4 key购买 nike

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:类型错误:对象 null 不可迭代(无法读取属性 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;
}
});

关于javascript - react js : TypeError: object null is not iterable (cannot read property Symbol(Symbol.迭代器)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55171969/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com