javascript - 由于 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 一起使用
解决方案
在 NextJS 中,您只能在客户端动态导入模块。你应该像这样导入它:
import dynamic from "next/dynamic"
const DynamicComponentWithNoSSR = dynamic(
() => import '~/config/ReactotronConfig',
{ ssr: false }
)
但我不确定 Reactotron 是否会按您期望的方式工作,因为我不知道这个库。
推荐阅读
- python - 使用 python 脚本的 Windows 服务器和 Windows 桌面尊重
- android - 错误:工具:在第 9 行指定属性 android:appComponentFactory 的替换,
- android - SnackBar 使用 ActionBar 主题?
- c# - c# - 如何通过在另一个带有if条件的文本框上输入事件从数据库中获取数据到文本框#
- android - 在下面的代码中,布局权重无法正常工作
- image - Xamarin 表单:在进行多张照片选择时,图片扩展不与路径一起保存在 android 中
- python - 使用 ForeignKey 查询集的 Django OneToMany 关系
- javascript - 带标签的引导下拉多选
- x86 - PCIe 枚举后 BIOS 卡住
- python - 为什么 vim red 突出显示 Django 模板中的结束标签?