Description
Hi,
I have a React component that loads server-side. In NodeJS, I get an error window not defined. AmCharts is bundled and rendered via webpack.
ReferenceError: window is not defined
at Object. (~/myproject/node_modules/amcharts3-react/index.js:1:1)
Code:
import React, { Component } from 'react'
import AmCharts from 'amcharts3-react' //window not defined error is here
const config = {...}
class MyChart extends Component {
render() { return <AmCharts {...config} />)
}
I am using the following workaround, but I don't think I should have to do this if AmCharts either can allow server-side rendering OR check presence of window.
var AmCharts = {}
if (process.browser) {
AmCharts = require('amcharts3-react')
}
class MyChart extends Component {
if (process.browser) return null;
render() { return <AmCharts {...config} />)
}
Of course a problem with the above approach is, I get the React warning in Browser console:
Warning: React attempted to reuse markup in a container but the checksum was invalid.
Is there anyway AmCharts React can check for this? Thanks!