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 }
I have problem
react js : TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))
31 Answer
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; } });