Reputation: 11
I am trying to set value in text input using the UseRef hook.
inputEl.current.value = "hello"
but it is not working.
Upvotes: 0
Views: 1373
Reputation: 2359
You can use
let textInput = React.useRef(null);
const [text, setText] = React.useState('');
<TextInput
ref={(input) => textInput = input}
value={text}
placeholder='Enter here'
onChangeText={(value) => setText(value)}
/>
Upvotes: 2
Reputation: 119
const val = inputEl.current.value = "hello"
<input type = "text" value = {val} ref = {inputEl}/>
provide obtained value using value attribute
Upvotes: 0