【问题标题】:Reactotron doesn't work with NextJS because of SSR由于 SSR,Reactotron 不适用于 NextJS
【发布时间】:2020-05-28 13:48:43
【问题描述】:

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

【问题讨论】:

    标签: javascript reactjs frontend next.js reactotron


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-02
      • 2019-09-01
      • 2022-08-17
      • 2022-10-07
      • 2021-11-12
      • 2021-12-16
      • 1970-01-01
      • 2019-12-26
      相关资源
      最近更新 更多