【发布时间】:2020-03-30 14:40:31
【问题描述】:
我有一个像下面这样的子组件
import React, { Component } from 'react';
class InputText extends Component {
render = () => {
return (
<div className="form-group">
<label htmlFor={this.props.id}>{this.props.label}</label>
<input type={this.props.type} value={this.props.value} placeholder={this.props.placeholder} name={this.props.name} id={this.props.id} className= {"form-control "+ this.props.class} required={this.props.extraValue}/>
</div>
)
}
}
export default InputText
我在下面的父组件中调用它
<InputText class="" placeholder="Email here..." type="email" name="email" onChange={this.handleChange} extraValue={true} label={[<span className="text-danger">*</span>, " Email"]} />
我收到如下错误
Warning: Each child in a list should have a unique "key" prop.
Check the render method of `InputText`. It was passed a child from Register. See https://fb.me for more information.
in span (at Register.js:182)
in InputText (at Register.js:182)
【问题讨论】:
-
谢谢@norbitrial。我没有数组。那么如何生成唯一 ID 呢?
-
您正在为标签值传入一个数组。会不会是触发错误?
标签: reactjs key react-component