A
A
alexfrolov_xcx2017-10-21 16:23:25
React
alexfrolov_xcx, 2017-10-21 16:23:25

Why is setState not working, is there an error?

Why do I have an error in this case?59eb4a12615d0837076902.png59eb4a5f511d3981273412.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Stolyarov, 2017-10-21
@alexfrolov_xcx

Add to the constructor:

// This binding is necessary to make `this` work in the callback
this.handleSearchs = this.handleSearchs.bind(this);

Source : https://reactjs.org/docs/handling-events.html
I would like to add a question to those experienced in React:
is this like a hack / crutch, or is this normal practice?

S
Svyatoslav, 2017-10-21
@SvyatYa

The function is not bound to any context. Write either an arrow function Or put a binding on the function:handleSearch = event => {}
onChane={this.handleSearch.bind(this)}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question