Grokking React Native
0% completed
Introduction to Refs
The component below keeps two counters. One lives in state and the other lives in a ref, and each has its own button. Watch what the console prints when you press Add to ref three times, Add to state once, and Add to ref one more time.
import { useRef, useState } from 'react'; import { View, Text, Button } from 'react-native'; function PressCounter() { const [stateCount, setStateCount] = useState(0); const refCount = useRef(0); console.log('render'); const handleStatePress = () => { setStateCount(stateCount + 1); }; const handleRefPress = () => {
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%