Actually, I want to build something that can catch every keystroke when I want to type on the google search bar. is that possible to build in react native? without my own keyboard. it should get any input from anywhere like a keylogger
CodePudding user response:
maybe you can try listen change event of input for example:
let input = document.getElementById('myinput');
input.addEventListener('change', e => {
let value = e.target.value;
console.log('value',value);
});
CodePudding user response:
if you want your input to change as you type then you should follow something like this:
const [input, setInput] = useState('');
<TextInput
style={styles.input}
onChangeText={text => setInput(text)}
value={input}
placeholder="input some text"
placeholderTextColor="gray"
/>
This will make it so every keystroke will update the input
as well as deleting what was once written on it.
You should also have a cleaner logic in your submit
button or search
button to reset the input to an empty string again ''
so you are not left with the previous text and having to delete ir every time. Something like this:
onPress={() => {
//your submit trigger
setInput('');
}}