警告:React.createElement:类型无效-预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象。
这是组件ContTypeAhead:
<Typeahead
id={this.props.name}
name={this.props.name}
onChange={this.changeHandler}
onBlur={this.onBlurHandler}
onInputChange={this.inputChangeHandler}
options={this.state.typeAheadOptions}
placeholder={'Type for ' + this.props.label}
selected={this.state.selected}
/>
在另一个组件中使用上述组件,代码是:
<ContTypeAhead
label="Autex"
name="autex"
id="autex"
size="6"
options={[]}
url="settlements/getAutex"
selected={this.state.autex}
changed={this.autexChangedHandler}
wrongSelectionHandler={this.wrongTypeAheadSelectionHandler}
rightSelectionHandler={this.rightTypeAheadSelectionHandler}
/>;
将TypeScript与CRA一起使用。定义的道具和状态界面,每个字段为:any;
您忘记了将您的ContTypeAhead
声明为功能。const ContTypeAhead = props => {
。要么。类。class ContTypeAhead extends Component {
。
或者你不return(<ContTypeAhead />)
这确实很烦人,但是我解决了。错误背后的原因是,Typeahead...
,因此我们首先必须包含@types
和最新版本的Typeahead。清楚地检查所使用的键,因为在新版本中,“ name”不是Typeahead的一部分。与日历相同。因此引起了问题。删除那些可以解决问题。
谢谢!