I have a button and a text bar. when the button is clicked, it will send the url entered in the text bar to an API and get the response. I think this can be solved with the setState() Callback function. But i am Not able to understand how to implement it.....
class App extends Component {
constructor() {
super();
this.state = {
input:'',
imageUrl:''
}
}
onInputChange=(event) => {
this.setState=({input: event.target.value});
}
onButtonSubmit = () => {
app.models.predict(Clarifai.COLOR_MODEL,this.state.input).then(
function(response) {
console.log(response);
},
function(err) {
// there was an error
}
);
}
render() {
<ImageLinkForm onInputChange={this.onInputChange} onButtonSubmit=
{this.onButtonSubmit} />
<FaceRecognition imageUrl={this.state.imageUrl} />
</div>
);
}
}
export default App;
constructor()method, it will automatically be called with thepropsobject and yes this is the samepropsobject you use in functional components. When you definesuper()you also have to pass inpropslike so:super(props);.