Неконтролируемый инпут Flashcards

1
Q

Неконтролируемый инпут

A

export const TrackValueOfUncontrolledInput = () => {
const actualValue = event.currentTarget.value;
setValue(actualValue)}
return <><input onChange = {onChange}/>- {value}</>
}

export const GetValueOfUnControlledInputByButtonPress = () => {
const [value, setValue] = useState(‘’)
const inputRef = useRef<HTMLInputElement>(null);</HTMLInputElement>

const save = () => {
const el = inputRef.current as HTMLInputElement;
setValue(el.value)
}
return <><input ref={inputRef}/> <button onClick={save}>save</button> - actual value: {value}</>
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly