Just a quick FYI regarding the first code example you posted. You do not have access to event.target.value
inside the setState updater function in React 16.4, which is what the curriculum is using. It would work in React 17 (I’m just talking about access to event.target.value
, not the incorrect state usage you have).
Example Codesandboxes
React 16 event.target inside setState updater function (will crash) - CodeSandbox
As for the second example. You have to “connect” the value
attribute to the state to make a controled component.