Answer the question
In order to leave comments, you need to log in
How to get value from Input on form submission using TypeScript?
Usually I did this with JS, but it doesn’t work with TS, an error is displayed :
Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'EventTarget'.
Property '0' does not exist on type 'EventTarget'
<form onSubmit={
(event) => {
event.preventDefault()
console.log(event.target[0].value)
}
}>
Answer the question
In order to leave comments, you need to log in
The value of input is in state.
Take it from there.
If there would be a normal layout, then console.log(event.target['test'].value)
(this example is from Vadim )
And you use react, so all values are taken from states, layout is only for rendering
<form onSubmit={
(event) => {
event.preventDefault()
console.log(inputCityValue)
}
}>
<Input value={inputCityValue} onChange={onChangeHandlerWrapper(setInputCityValue)}/>
<button type='submit'><span>Обновить данные</span></button>
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question