2016-10-19 20 views
0

我有陣營服務器端渲染和Recharts問題。 當我通過道具將數據傳遞給我的圖表,刷新我的服務器,並刷新我的網頁,我得到一個錯誤:陣營Recharts - 的ReferenceError:文件沒有定義

ReferenceError: document is not defined 
at Text.calculateWordWidths (/Users/piRstone/Documents/node/dashboard/node_modules/recharts/lib/component/Text.js:101:26) 
at Text.updateWordsByLines (/Users/piRstone/Documents/node/dashboard/node_modules/recharts/lib/component/Text.js:81:43) 
at Text.componentWillMount (/Users/piRstone/Documents/node/dashboard/node_modules/recharts/lib/component/Text.js:67:12) 
[...] 

即使我從圖表的文件常量通過靜態數據仍然不工作。

當我試圖Recharts沒有服務器端渲染,一切正常,但只要我設置SSR,我得到這個錯誤。

我試圖讓我的網頁正常顯示(當然沒有圖表),從圖表聲明刪除data={this.props.data},但如果如果重置此,我仍然得到這個錯誤。

我認爲這是我找到一個可行的解決方案the issue on Github作爲所述一個bug(可能解決,但顯然沒有)

回答

0

。我用終極版在我的項目,所以我使用的狀態返回或不是我的圖表。

render() { 
    if (browser) { 
     return (
      <div> 
       <AreaChart width={630} height={300} data={views.views} margin={{top: 5, right: 30, left: 20, bottom: 5}}> 
        // Code 
       </AreaChart> 
      </div> 
     ); 
    } else { 
     return null; 
    } 
} 

默認情況下,browser狀態爲false。我派遣一個行動來改變它的狀態時的坐騎成分:

componentDidMount() { 
    const {dispatch} = this.props; 
    if (typeof(document) != "undefined") { 
     dispatch(setOnBrowser(true)) 
    } 
} 

由於服務器已經通過道具發送的數據,該組件剛剛重新渲染,它爲我工作。

相關問題