Delay with updating input text in React Native

Viewed 600

When I type any input, the TextInput below briefly shows the default text before removing special characters and converting letters to upper case. For example, typing "/" briefly flashes "/" in the input before it's removed. Typing "r" briefly flashes "r" before changing to "R." How can I show only the value provided in my onChangeText function?

const TextInput = (props) => {
    const [text, setText] = useState("");
    const onChangeText = (newText) => {
        newText = newText.replace(/[^A-Za-z0-9]/g, '').toUpperCase();
        setText(newText);
    }

    return (
        <TextInput value={text} onChangeText={onChangeText} />
    );
}
0 Answers
Related