[英]react cannot set property of props of undefined
I have a simple component like this 我有一个像这样的简单组件
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>
)
}
}
The somewhere I do <SearchList placeholder="Search Area" />
我在某处执行
<SearchList placeholder="Search Area" />
Why I got error of cannot set property of props of undefined? 为什么会出现无法设置未定义道具属性的错误?
When you write a react component extending React.Component
you don't need the extra ()
after React.Component
当您编写扩展
React.Component
组件时,在React.Component
之后不需要多余的()
Use this 用这个
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>
)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.