MCPcopy Create free account
hub / github.com/dabbott/react-native-express / App

Function App

examples/files/hooks/useRef.js:4–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { View, Text, Button } from 'react-native'
3
4export default function App() {
5 const intervalRef = useRef()
6 const [count, setCount] = useState(0)
7
8 useEffect(() => {
9 intervalRef.current = setInterval(
10 () => setCount((count) => count + 1),
11 1000
12 )
13
14 return () => {
15 clearInterval(intervalRef.current)
16 }
17 }, [])
18
19 return (
20 <View>
21 <Text style={{ fontSize: 120 }}>{count}</Text>
22 <Button
23 title="Stop"
24 onPress={() => {
25 clearInterval(intervalRef.current)
26 }}
27 />
28 </View>
29 )
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected