简体   繁体   English

我不能亲自 todos 反应本机 firestore

[英]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)

Read the docs for reference阅读文档以供参考

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.

相关问题 无法将 Firestore 文档数据加载到 React-Native 中的变量 - Can't load firestore document data to variable in React-Native 无法从 Firestore React-Native 获取所有数据 - Can't fetch all data from Firestore React-Native 无法从 React-Native-Firebase(v6) Firestore 获取数据:undefined 不是函数(靠近“...this._firestore.native.collectionGet...”) - Can't get data from React-Native-Firebase(v6) Firestore: undefined is not a function (near '...this._firestore.native.collectionGet...') React-Native 无法从 Firestore 响应中访问二级 - React-Native can't access second level from firestore response 反应本机 firestore 时间戳 - react native firestore timestamps 我应该如何将 firestore object 转换成我可以在 expo/react-native 中使用的东西? - How should I convert a firestore object into something I can use in expo/react-native? 我无法访问 firestore 数据库中的两个子集合之一。 反应 - I can't access one of two subcollections in firestore data base. React 使用 React Native 在平面列表中 Firestore 数据 - Firestore data in a flatlist with react native 我创建并保存了用户的 email,但我无法执行 email 更新。 使用 firebase,firestore 和 react - I have the create and saving of the user's email, but I can't do an email update. Use firebase, firestore and react 我无法按多个字段订购我的 Firestore 数据。 反应 - I can't order my firestore data by multiple fields. React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM