【发布时间】:2020-02-16 06:31:14
【问题描述】:
我正在使用 Firebase Cloud Functions 来托管我的 SSR Nextjs 应用。我可以在 firebase 云函数上部署 Nextjs 应用程序,并在没有 React Hooks 的情况下使用干净的 URL 访问它,但使用 React Hooks 我收到一条错误消息:
Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
This issue has also been reported here 在 GitHub firebase/firebase-functions 存储库中。
还有一个reproducible example repo 用于测试错误(pages/about.tsx 文件中实现的 useState 挂钩)。
这是在 React: 16.10.2 上完成的
【问题讨论】:
-
我目前正在开发 Next.js 应用程序,该应用程序使用 Hooks 并且需要部署到 Firebase,所以如果我能做到这一点且没有错误,我会及时通知您 :)
-
@RomanBatsenko,这个firebase gcp nextjs setup 为我工作????我没有发布答案,因为我没有花时间弄清楚是什么真正导致了其他设置中的错误。我认为这将是 gcp 示例中 babel 的存在,仅此而已。如果您想出一个可行的解释,请更新我们的答案!
-
哇,太棒了! ????好的,如果我弄清楚发生了什么,我会写在这里
标签: reactjs firebase google-cloud-functions react-hooks next.js