A callback work which will be conjured when setState has completed and the part is re-rendered.
Something that is not talked about a great deal is that setState is asynchronous, which is the reason it takes in a moment callback function. Ordinarily it's best to utilize another lifecycle strategy instead of depending on this callback function, however, it's great to know it exists.
1 2 3 4 5 6 7 8 9 10 11 | Class Training extends Course { this.state = { sampleItem: 'learn', } handleChange = (event) => { console.log(this.state.sampleItem) this.setState({ sampleItem: event.target.value //event.target.value = Welcome }, () => console.log(this.state.sampleItem)) }; |
Output:
Learn
Welcome