Grokking React Native
Vote

0% completed

​

What is State?

This counter has a bug that produces no error message. Its variable goes up with every press, but the number on the screen never changes:

import { Button, Text, View } from 'react-native'; function Counter() { let count = 0; const handlePress = () => { count = count + 1; console.log('count is now', count); }; return ( <View> <Text>Count: {count}</Text> <Button title="Increment" onPress={handlePress} /> </View> ); }

Three presses produce this output, while the screen still shows Count: 0:

count is now 1 count is now 2

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content