我想根據瀏覽器窗口的當前大小來設置組件的狀態。服務器端渲染已被使用(React + Redux)。我正考慮使用Redux商店作爲膠水 - 只是爲了更新商店的大小。 有沒有其他/更好的解決方案,不涉及Redux。 謝謝。React同構渲染 - 處理窗口大小調整事件
class FocalImage extends Component {
// won't work - the backend rendering is used
// componentDidMount() {
// window.addEventListener(...);
//}
//componentWillUnmount() {
// window.removeEventListener('resize' ....);
//}
onresize(e) {
//
}
render() {
const {src, className, nativeWidth, nativeHeight} = this.props;
return (
<div className={cn(className, s.focalImage)}>
<div className={s.imageWrapper}>
<img src={src} className={_compare_ratios_ ? s.tall : s.wide}/>
</div>
</div>
);
}
}
'componentDidMount'不叫服務器端渲染。 – xiaofan2406