Reputation: 55
React.useEffect(() => {
const fetchData = async () => {
const db = firebase.firestore();
db.collection('users')
.onSnapshot(snapshot =>
setSpells(
snapshot.docs.map(doc => ({
id: doc.id,
...doc.data()
}))
)
);
};
fetchData();
}, []);
mapped out like this
{spells.map(spell => (
<li key={spell.id}>
<SpellInput spell={spell} />
</li>
))}
update and deleted like this
const onUpdate = () => {
const db = firebase.firestore();
db.collection('users')
.doc(spell.id)
.set({ ...spell, name });
};
const onDelete = () => {
const db = firebase.firestore();
db.collection('users').doc(spell.id).delete();
};
can't seem to delete or edit the first item on the list on firebase. Can someone explain why?
here's my repo https://github.com/isabelchua/CRUD
Upvotes: 1
Views: 166
Reputation: 55
I found the solution
id: doc.id, ...doc.data()
should be
...doc.data(), id: doc.id,
Upvotes: 1