MCPcopy Index your code
hub / github.com/FirebaseExtended/reactfire / Counter

Function Counter

example/withoutSuspense/Firestore.tsx:11–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import { getFirestore } from 'firebase/firestore';
10
11const Counter = () => {
12 const firestore = useFirestore();
13 const ref = doc(firestore, 'count', 'counter');
14 const { status, data: count } = useFirestoreDocData(ref);
15
16 const incrementCounter = (amountToIncrement) => {
17 updateDoc(ref, {
18 value: increment(amountToIncrement),
19 });
20 };
21
22 if (status === 'loading') {
23 return <LoadingSpinner />;
24 }
25
26 return (
27 <>
28 <button onClick={() => incrementCounter(-1)}>-</button>
29 <span> {(count as any).value} </span>
30 <button onClick={() => incrementCounter(1)}>+</button>
31 </>
32 );
33};
34
35const AnimalsList = () => {
36 const firestore = useFirestore();

Callers

nothing calls this directly

Calls 3

useFirestoreFunction · 0.85
useFirestoreDocDataFunction · 0.85
incrementCounterFunction · 0.70

Tested by

no test coverage detected