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

Function Counter

example/withSuspense/Firestore.tsx:18–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16import { initializeFirestore, doc, collection, enableIndexedDbPersistence, increment, updateDoc, orderBy, query, addDoc, deleteDoc, DocumentData } from 'firebase/firestore';
17
18const Counter = () => {
19 const firestore = useFirestore();
20
21 const ref = doc(firestore, 'count', 'counter');
22
23 const incrementCounter = (amountToIncrement) => {
24 updateDoc(ref, {
25 value: increment(amountToIncrement),
26 });
27 };
28
29 const { data: count } = useFirestoreDocData(ref);
30
31 return (
32 <>
33 <button onClick={() => incrementCounter(-1)}>-</button>
34 <span> {(count as any).value} </span>
35 <button onClick={() => incrementCounter(1)}>+</button>
36 </>
37 );
38};
39
40const StaticValue = () => {
41 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