React報錯:Can't perform a React state update on an unmounted component

antd中的Table組件的scroll參數,需要隨着頁面的變化而動態的變化;

this.state = {
	height: document.body.clientHeight
};
componentDidMount () {
	window.addEventListener('resize', this.handleHeight.bind(this));
	//動態獲取頁面高度
}
componentWillUnmount () {
	window.removeEventListener('resize', this.handleHeight.bind(this));
	this.setState = () => {
		return;
	};
	//在組件銷燬時清除所有的state狀態
}
handleHeight () {
	const height = document.body.clientHeight;
	this.setState({
		height
	});
}
render () {
	const { height } = this.state;
	return (
		<Table scroll={{y: height}}></Table>
	)
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章