How does this update the text on every change?

Question

In the context of this exercise, how does this update the text on every change?

Answer

The way this works is generally as follows.

Every time we change the input of the text field, whether by adding or deleting some text, it will trigger the onChange attribute’s function, handleUserInput(). When this function is invoked, it will update the state of the component to the current value of the text field using setState(). Any time setState() is called for a component, it will trigger a call to the render() method, which will re-display the text to the latest value of the text field.

6 Likes

Great explanation! I really enjoy your answers. They are clear, to the point and concise.

5 Likes