Skip to content
Advertisement

onChange not working on the first input into the text field

onChange event doesn’t return the first change of the text input but works on subsequent changes. Sorry if this is obvious, I’m new to React.

JavaScript

Advertisement

Answer

When you call setLocation(text);, handleClick will finish execution before the location value is actually updated.

There is no need for location and setLocation; looks like maybe location is supposed to be the same as text.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement