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 }

I have problem

react js : TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))

3

1 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; } }); 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like