我正在为我的NextJS应用程序配置redux存储,通常使用Reactotron库检查存储。但是,NextJS是服务器端渲染,如果我在应用程序文件中导入配置,则会给出错误window is not defined

那是我的配置文件:
https://github.com/LauraBeatris/amazon-next/blob/develop/src/config/ReactotronConfig.js

和我的应用程序文件:
https://github.com/LauraBeatris/amazon-next/blob/develop/src/pages/_app.js

我想知道是否有一种将Reactotron与NextJS结合使用的方法

最佳答案

在NextJS中,您只能在客户端动态导入模块。您应该像this一样导入它:

import dynamic from "next/dynamic"

const DynamicComponentWithNoSSR = dynamic(
  () =>  import '~/config/ReactotronConfig',
  { ssr: false }
)


但是我不确定Reactotron是否会按您期望的方式工作,因为我不知道该库。

关于javascript - 由于SSR,Reactotron无法与NextJS一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60197905/

10-12 13:19