我正在尝试构建一个React,但是对于React/RN生态系统来说还是有点陌生,所以我可能只是误解了我所遇到的问题。
我有一个应用程序,其中很多页面的结构如下:
<View>
<NavComponent />
<View>
{/* Page component structure/logic here */}
</View>
</View>
NavComponent加载带有TouchableOpacity元素的可切换导航菜单,如下所示:
Go to Screen #1
Go to Screen
我不太明白useEffect清理功能是如何工作的。因为无论我做什么我都会收到警告:
警告:无法对未挂载的组件执行反应状态更新。这是一个非操作,但它表示您的应用程序中存在内存泄漏。若要修复,请取消useEffect清理函数中的所有订阅和异步任务。
这是我的代码:
useEffect(() => {
setLoading(true)
// Get position list
const getPositionList = db.collection('lists').doc('positions').get(
我有一个处理Firebase身份验证的useEffect。当我签署,然后再次登录,我看到这种效果是两次调用。每次我签到和回来的时候,都会被称为额外的时间。
我有一种感觉,我需要用一个清理函数来处理这个问题,但是我不知道怎么写它。
这是我的钩子:
useEffect(() => {
console.log('RUNNING THE EFFECT');
function routeUser(user) {
// Redirect user somewhere depending on user state
}
function setupUser(us
我正在使用Firebase v9,我正在构建一个聊天应用程序,在调用onSnapShot获取聊天数据之前,我需要做一些异步工作: const getChat = async () => {
// I need to await for user data before doing anything else.
// I'll need some user data to build the query which
// I'll be using in onSnapShot later on.
当尝试运行下面的代码时,我继续收到以下错误:Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. 我已经在代码中指出了错误出现的地方,但我不确定我是否理解了上面的错误,并正在寻找如何解决
我所有的单元测试都通过了。但是,引发的错误如下:
Chrome 74.0.3729 (Linux 0.0.0) ERROR
An error was thrown in afterAll
Uncaught TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. thrown
Chrome 74.0.3729 (Linux 0.0.0): Executed 20 of 79 (sk
useEffect(() => {
// parameter is the user state of the auth
// onAuthStateChanged: method from auth library
const unsubscribeFromAuth = auth.onAuthStateChanged(user => {
setCurrentUser(user);
})
// returned function will be called on component unmount
return () =