Alex
Alex

Reputation: 1

TextInput blinking / flickering when I format text in `onChangeText` React Native

I'm trying a simple example of dynamic input formatting if input = 3 => save text, else - text old:

const [text, setText] = useState('');

return(
    <View>
        <TextInput
            value={text}
            onChangeText={innerText => {
                if (innerText === '3')
                    setText(innerText);
                }}
        />
    </View>)

What happens: I enter anything, try to correct the input - I get the input blinking for a few seconds - the value that I enter from the keyboard appears for a moment, then returns to the previous state, thanks to the "filter" in onChangeText (for example, you can enter only the number 3, and when entering the rest - I actually see all the characters that I enter for some time, and only then they are erased in accordance with the value). How to avoid this?

How to avoid this? I tried a bunch of ways:

Upvotes: 0

Views: 122

Answers (0)

Related Questions