首页 > 解决方案 > 由于 SSR,Reactotron 不适用于 NextJS

问题描述

我正在为我的 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 一起使用

标签: javascriptreactjsfrontendnext.jsreactotron

解决方案


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

import dynamic from "next/dynamic"

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

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


推荐阅读