小编utu*_*rnr的帖子

使用useEffect,如何跳过对初始渲染应用效果?

使用React的新效果钩子,如果重新渲染之间某些值没有改变,我可以告诉React跳过应用效果 - 来自React的文档示例:

useEffect(() => {
  document.title = `You clicked ${count} times`;
}, [count]); // Only re-run the effect if count changes
Run Code Online (Sandbox Code Playgroud)

但是上面的例子应用了初始渲染时的效果,以及后续重新渲染的位置count.如何告诉React跳过初始渲染的效果?

reactjs react-hooks

28
推荐指数
7
解决办法
1万
查看次数

我可以使用firestore获取使用batch()创建的文档的生成ID吗?

有没有办法可以使用Firestore获取作为批处理的一部分创建的文档的自动生成的ID?

使用时.add()我可以很容易地获得一个ID:

db.collection('posts')
  .add({title: 'Hello World'})
  .then(function(docRef) {
    console.log('The auto-generated ID is', docRef.id)
    postKey = docRef.id
});
Run Code Online (Sandbox Code Playgroud)

使用.batch()我可以使用.doc()和添加文档.set():

const batch = db.batch();

const postsRef = db.collection('posts').doc(postKey);
batch.set(postsRef, {title: 'Hello Again, World'});

const votesRef = db.collection('posts').doc(postKey)
                   .collection('votes').doc();
batch.set(votesRef, {upvote: true})

batch.commit().then(function() {
});
Run Code Online (Sandbox Code Playgroud)

我可以获取添加到的文档的自动生成的ID votes吗?

更新:

Doug Stevenson是正确的 - 我可以访问ID votesRef.id

javascript firebase google-cloud-firestore

13
推荐指数
1
解决办法
5000
查看次数