react cannot set property of props of undefined

前端 未结 1 892
忘了有多久
忘了有多久 2021-01-21 20:29

I have a simple component like this

import { Component } from \'react\'

export default class SearchList extends Component(){
    constructor(props){
        sup         


        
相关标签:
1条回答
  • 2021-01-21 21:04

    When you write a react component extending React.Component you don't need the extra () after 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>
            )
        }
    }
    
    0 讨论(0)
提交回复
热议问题