Jammming project - TypeError: Cannot read property 'term' of null

Hi in the project Jamming i have this problem:
After doing all when i click on Search appear that problem. I also add onClick={this.search} to the button. Someone know how to fix? Thanks

TypeError: Cannot read property ‘term’ of null
SearchBar.search

10 |    }
  11 | 
  12 |    search() {
> 13 |        this.props.onSearch(this.state.term);
     | ^  14 |    }
  15 | 
  16 |    handleTermChange(event) {

My code

class SearchBar extends Component {

    constructor(props) {

        super();

        this.search = this.search.bind(this);

        this.handleTermChange = this.handleTermChange.bind(this)

    }

    search() {

        this.props.onSearch(this.state.term);

    }

    handleTermChange(event) {

        this.setState = ({ term: event.target.value })

    }

    render() {

        return (

            <div className="SearchBar">

                <input placeholder="Enter A Song, Album, or Artist" onChange={this.handleTermChange} />

                <button className="SearchButton" onClick={this.search}>SEARCH</button>

            </div>

        )

    }

}
1 Like