[英]i can't personally todos react native firestore
I made a todo app using firebase. I store the todos in firestore and save the email address of the user who added the todo into the document.我使用 firebase 做了一个 todo 应用程序。我将 todos 存储在 firestore 中,并将添加 todo 的用户的 email 地址保存到文档中。 but when a user saves todo, all users see that todo.
但是当用户保存待办事项时,所有用户都会看到该待办事项。 my codes:
我的代码:
const [dailys, setDailys] = useState([]);
const dailyRef = firebase.firestore().collection('daily');
const [addDaily, setAddDaily] = useState('');
const email = firebase.auth().currentUser.email;
useEffect(() => {
async function check() {
dailyRef.orderBy('createdAt', 'desc')
.onSnapshot(
querySnapShot => {
const dailys = []
querySnapShot.forEach((doc) => {
const { heading } = doc.data()
dailys.push({
id: doc.id,
heading,
email: email,
})
})
setDailys(dailys)
}
)
}
check()
}, [])
const addDailyPlan = () => {
if (addDaily && addDaily.length > 0) {
const timeStamp = firebase.firestore.FieldValue.serverTimestamp();
const daily = {
email:email,
heading: addDaily,
createdAt: timeStamp
};
dailyRef
.add(daily)
.then(() => {
setAddDaily('');
Keyboard.dismiss();
})
.catch((error) => {
alert(error);
})
}
}
render(
<FlatList data={dailys}/>
) )
If everyone is pushing in the same collection, everyone will have the same result...如果每个人都推同一个集合,每个人都会有相同的结果......
Either create a specific collection for each user (recommended), or add this to your query => where("email", "==", email)为每个用户创建一个特定的集合(推荐),或者将其添加到您的查询中 => where("email", "==", email)
const email = firebase.auth().currentUser.email;
const dailyRef = firebase.firestore().collection('daily');
setDoc(doc(dailyRef,email ), {
name:"name",
email:email });
const q = query(dailyRef, where("email", "==", email));
I followed your advice and used a code in the above structure.我听从了您的建议并使用了上述结构中的代码。 but I am getting an error like this: [Unhandled promise rejection: TypeError: t._freezeSettings is not a function. (In 't._freezeSettings()', 't._freezeSettings' is undefined)]
但我收到这样的错误:[Unhandled promise rejection: TypeError: t._freezeSettings is not a function. (In 't._freezeSettings()', 't._freezeSettings' is undefined)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.