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

Function List

example/withSuspense/Firestore.tsx:50–80  ·  view source on GitHub ↗
({ query, removeAnimal })

Source from the content-addressed store, hash-verified

48};
49
50const List = ({ query, removeAnimal }) => {
51 const { data: animals } = useFirestoreCollectionData(query, { idField: 'id' });
52 return (
53 <>
54 <div className="h-20 overflow-x-scroll shadow-inner m-2 border border-black">
55 <ul>
56 {(animals as Array<{ id: string; commonName: string }>).map((animal) => (
57 <li key={animal.id}>
58 {animal.commonName} <button onClick={() => removeAnimal(animal.id)}>X</button>
59 </li>
60 ))}
61 </ul>
62 </div>
63 <ul>
64 {Array.from(
65 (animals as any[]).reduce((animalCountMap, animal) => {
66 const currentCount = animalCountMap.get(animal.commonName) ?? 0;
67 return animalCountMap.set(animal.commonName, currentCount + 1);
68 }, new Map<string, number>())
69 ).map((animalStat) => {
70 const [animalName, animalCount] = (animalStat as [string, number]);
71 return (
72 <li key={animalName}>
73 {animalName}: {animalCount}
74 </li>
75 );
76 })}
77 </ul>
78 </>
79 );
80};
81
82const FavoriteAnimals = (props) => {
83 const firestore = useFirestore();

Callers

nothing calls this directly

Calls 2

removeAnimalFunction · 0.85

Tested by

no test coverage detected