我有一个像这样的简单组件
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>
)
}
}
我做的某个地方<SearchList placeholder="Search Area" />
为什么我的错误无法设置undefined的道具属性?
答案 0 :(得分:5)
当你编写一个延长React.Component
的反应组件时,()
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>
)
}
}