I am having some issues figuring out how I can get the state of an inputfield, and add it to an useState array.
The way this code is set up, using onChange, it will add every character I type in the textField as a new part of the array, but I dont want to set the value until the user is done typing.
What would be a simple solution to this?
My code:
const [subject, setSubject] = useState([]);`
<input type="text" placeholder={"Eks. 'some example'"} onChange={(e) => setSubject(oldArray => [...oldArray, e.target.value])}/>
onBlurfor loss of focus (which is when the vanilla 'change' event would usually trigger for an input, React's onChange is actually equivalent to 'input') otherwise you'll need to set your own parameters for what constitutes 'done typing' ie debounce the handler or the like.onBlurto determine whether the user has stopped typing like @pilchard suggests, or you use a button with anonClick, just add that input state to the the main state.setTimeout) if you want it to add when the user is "done typing" (not well defined), or include a different mechanism, such as when the user clicks a separate button or perhaps loses focus from the input.