この質問は何度か答えられたと思いますが、具体的なケースは見つかりません。だから、基本的に私は(それが高い場合、偽)画面のサイズが変更と未満500pxなどされている場合はtrueに状態コール「isSmall」に変更し、アクションをトリガーするアプリケーションコンポーネントを持ってReact/Reduxコンポーネントが状態変更時に再レンダリングされない
https://codesandbox.io/s/jjy9l3003
class App extends React.Component {
...
resizeHandeler(e) {
const { window, dispatch } = this.props;
if (window.innerWidth < 500 && !this.state.isSmall) {
dispatch(isSmallAction(true));
this.setState({ isSmall: true });
} else if (window.innerWidth >= 500 && this.state.isSmall) {
dispatch(isSmallAction(false));
console.log(isSmallAction(false));
this.setState({ isSmall: false })
}
};
componentDidMount() {
const { window } = this.props;
window.addEventListener('resize', this.resizeHandeler.bind(this));
}
...
私はHeaderContainerと呼ばれる、Appの子でStoreに接続され、状態が "isSmall"であるため、 "isSmall"変更状態のときにこのコンポーネントを再レンダリングします。
class Header extends React.Component {
constructor(props) {
super(props);
this.isSmall = props.isSmall;
this.isHome = props.isHome;
}
...
render() {
return (
<div>
{
this.isSmall
?
(<div>Is small</div>)
:
(<div>is BIG</div>)
}
</div>
);
}
...
私はコンソールを介して見ることができますが、還元は実際にはヘッダーコンポーネントが再レンダリングされていないストアを更新しています。 誰かが私が逃していることを指摘できますか?
私は "connect()" redux-react関数を誤解していますか?
はあなたに感謝し、それは今SENSを作ります – Sylou