创建reactfire挂钩时避免重复调用

问题描述

使用reactfire初始化组件时,每次我添加reactfire钩子(例如useFirestoreDocData)时,它都会触发重新渲染,因此会重复所有以前的初始化。例如:

const MyComponent = props => {
  console.log(1);
  const firestore = useFirestore();
  console.log(2);
  const ref = firestore.doc('count/counter');
  console.log(3);
  const { value } = useFirestoreDocDataOnce(ref);
  console.log(4);
  ...
  return <span>{value}</span>;
};

将输出:

1
1
2
3
1
2
3
4

这似乎很浪费,有办法避免这种情况吗?

当我需要一个reactfire钩子的结果来创建另一个(例如,从一个文档中检索数据以确定要读取的其他文档)并重复服务器调用时,这尤其成问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)