Said Mounaim
Said Mounaim

Reputation: 1

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))

Upvotes: 0

Views: 12829

Answers (1)

tinwan
tinwan

Reputation: 307

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

Upvotes: 1

Related Questions