Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6365

React Native setState Flickering

$
0
0

I have something very simple to do, which I have done before, and now doesn't seem to work. I just need a number to go up once every second and then display it.Here is my code:

const counter = () => {    let i: number = 0    setInterval(() => {        i += 1    }, 1000)    const [number, setNumber] = useState(0)    setInterval(() => { setNumber(i) }, 1000)    return (<Text>{number}</Text>    )}

This is very simple and yet doesn't work. What happens is that the number flickers, going between numbers up and down as it slowly climbs up the number line. It's... not great


Viewing all articles
Browse latest Browse all 6365

Trending Articles