Pencere nesnesinde yeniden boyutlandırma olayı için bir olay dinleyicim olduğu bir React Uygulaması var.React yeniden boyutlandırma bileşenleri değiştir
class App extends React.Component {
constructor(props){
super(props);
this.state = { width: 0 }
this.setSize = this.setSize.bind(this);
}
render() {
let content = this.state.width < 600 ? <MobileComponent/> : <DesktopComponent />;
return(<div>{content}</div>)
}
setSize() {
this.setState({
width: window.innerWidth
});
}
componentDidMount() {
this.setSize();
window.addEventListener('resize', this.setSize);
}
componentWillUnmount() {
window.removeEventListener('resize', this.setSize);
}
}
Bu şey iş ama benim sorunum ben çocuk bileşenleri içine Uygulama bileşeni (pencere genişliği) durumunu erişmek için nasıl bilmiyorum olmasıdır.
Yani birinin/erişmek (i sahne ile gönderebilir biliyorum, ama benim, ben 2 daha fazla bileşen ne varsa?)
bunu sahne üzerinden yapabilir ve çok sayıda alt öğe bileşenine gönderebilirsiniz. – Ved