为什么使用异步useEffect会收到“ TypeError:r不是一个函数”?

时间:2019-05-02 17:38:45

标签: reactjs react-hooks

我有一个使用钩子的工作组件。我基本上有一个很小的两页插件这样的代码:

const page = firstPage ? <FirstPage> : <SecondPage />

一切正常。我正确设置了状态以更新到第二页。

第二秒钟,我在useEffect中添加FirstPage,一旦输入"TypeError: r is not a function"的方法,我就会从最小的FB代码中得到错误SecondPage

// This is in FirstPage, but causing an exception in SecondPage
useEffect(async () => {
}, []);

第二页只是缩小为:

import React, { useContext } from 'react';
export default function SecondPage(props) {
  return <div>Here i am</div>
}

我可以在console.log内进行SecondPage的操作,因此我认为清理FirstPage时会出现一些异步错误。

async中删除useEffect可解决问题。不知道为什么会这样。我看过使用async的示例。

0 个答案:

没有答案
相关问题