我有一个像这样的简单组件
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" />
<SearchList placeholder="Search Area" />
为什么会出现无法设置未定义道具属性的错误?
当您编写一个react组件扩展时,React.Component您不需要额外的()时间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> ) } }