0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[WIP] Nextjs で react-json-viewで `window is not defined` がでたときの対処 

0
Posted at

詳細は後ほど書く。(必ず)

スクリーンショット 2021-09-13 3.41.12.png

対策

以下のようにdynamic importを使う

import React from 'react'
import { ScrollBox } from '../Common/ScrollBox'
// import ReactJson from 'react-json-view'
import dynamic from 'next/dynamic'
// `window is not defined`対応のため、Dynamic Importを使っています。 https://zenn.dev/ninomium/articles/5fed8af69640a6
const ReactJson = dynamic(() => import('react-json-view'))
// import { CodeDebugger } from '../CodeDebugger'

interface Props {
  src?: any
  width?: string
  height?: string
}

const ReactJsonViewContainer = ({ src = null, width = '100%', height = '100%' }: Props) => {
  // console.log(src, 'json')
  //
  return src ? (
    <ScrollBox width={width} height={height}>
      <ReactJson src={src} />
      {/* {CodeDebugger(src)} */}
    </ScrollBox>
  ) : null
}

export default ReactJsonViewContainer

参考
Next.jsでwindow is not defined を解決する(依存ライブラリ対応)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?