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

Function Counter

example/withoutSuspense/RealtimeDatabase.tsx:10–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import { AuthWrapper } from './Auth';
9
10const Counter = () => {
11 const database = useDatabase();
12 const counterRef = ref(database, 'counter');
13 const increment = amountToIncrement => {
14 return set(counterRef, rtdbIncrement(amountToIncrement));
15 };
16
17 const response = useDatabaseObjectData(counterRef);
18
19 const { status, data: count } = response;
20 if (status === 'loading') {
21 return <LoadingSpinner />;
22 }
23
24 return (
25 <>
26 <button onClick={() => increment(-1)}>-</button>
27 <span> {count as any} </span>
28 <button onClick={() => increment(1)}>+</button>
29 </>
30 );
31};
32
33const AnimalsList = () => {
34 const database = useDatabase();

Callers

nothing calls this directly

Calls 3

useDatabaseFunction · 0.85
useDatabaseObjectDataFunction · 0.85
incrementFunction · 0.70

Tested by

no test coverage detected