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

标签 javascript reactjs

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/

相关文章:

html - React.js 样式组件 : Adding HTML attributes

reactjs - 使用 React 从 monorepo 中的另一个包导入 JSX 文件时出错

reactjs - 使用 NextJS 减少 JS 执行时间

javascript - JQuery 选择器不起作用,而循环起作用。为什么?

javascript - typescript map : key and value swapped on iteration

javascript - CKEditor5,如何在我的 javascript 函数中编写 Blur 事件处理程序

javascript - Import.meta.env 在生产构建 vitejs 上未定义

javascript - 如何在 TypeScript 的 Vue Composition API 中响应式访问当前路由名称?

javascript - jquery 仅在搜索中没有返回结果时才显示 div

javascript - 使用 TypeScript 和 Redux 响应惰性