이 질문은 여러 번 답변 된 것으로 생각되지만 구체적인 사례를 찾을 수 없습니다.React/Redux 구성 요소가 상태 변경시 다시 렌더링되지 않음
https://codesandbox.io/s/jjy9l3003
그래서 기본적으로 나는 (이 높은 경우는 false) 화면 크기를 조정할 미만 500 픽셀을 경우 true로 상태 호출 "isSmall"로 변경 작업
를 트리거 앱 구성 요소가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의 하위이며 저장소와 상태 "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>
);
}
...
비록 내가 콘솔을 통해 볼 수 있다면 redux가 실제로 저장소 요소를 업데이트하고 있습니다. 헤더 구성 요소가 다시 렌더링되지 않습니다. 누군가 내가 누락 된 부분을 지적 할 수 있습니까?
"connect()"redux-react 함수를 잘못 이해하고 있습니까?
감사합니다, 그것은 만들 SENS를 – Sylou