Javascript react无法设置未定义道具的属性
我有一个像这样的简单组件Javascript react无法设置未定义道具的属性,javascript,reactjs,Javascript,Reactjs,我有一个像这样的简单组件 import { Component } from 'react' export default class SearchList extends Component(){ constructor(props){ super(props); } render(){ const { placeholder } = this.props; return( <div cla
import { Component } from 'react'
export default class SearchList extends Component(){
constructor(props){
super(props);
}
render(){
const { placeholder } = this.props;
return(
<div className="searchList">
<input type="text" placeholder={placeholder}/>
<button>Search</button>
</div>
)
}
}
从'react'导入{Component}
导出默认类SearchList扩展组件(){
建造师(道具){
超级(道具);
}
render(){
const{placeholder}=this.props;
返回(
搜寻
)
}
}
我在某处做的事
为什么我出现了无法设置未定义道具属性的错误?当您编写一个扩展
react.component
的react组件时,您不需要在react.component
之后额外的()
用这个
export default class SearchList extends Component{
constructor(props){
super(props);
}
render(){
const { placeholder } = this.props;
return(
<div className="searchList">
<input type="text" placeholder={placeholder}/>
<button>Search</button>
</div>
)
}
}
导出默认类SearchList扩展组件{
建造师(道具){
超级(道具);
}
render(){
const{placeholder}=this.props;
返回(
搜寻
)
}
}
export default class SearchList extends Component()中的remove(),哎哟,真是个粗心的错误。