Grokking React Native
Vote

0% completed

​

Updating and Accessing Refs

The screen below reports Ref Counter: 0 after you press Increment Ref twice, even though the console shows that the ref holds 2. Nothing is broken. The behavior follows directly from how refs and rendering work, and understanding it tells you where a ref may be read.

import { useRef, useState } from 'react'; import { View, Text, Button } from 'react-native'; function RefCounter() { const countRef = useRef(0); const [refreshCount, setRefreshCount] = useState(0); const handleIncrementPress = () => { countRef.current += 1; console.log('countRef.current is', countRef

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content