<Provider store={this.props.store}>
<ConnectedRouter history={this.props.history}>
<AppWrap>
<Header />
<Main>
<Switch>
<Route exact path="/" component={Component1}/>
<Route path="/component2" component={Component2}/>
</Switch>
</Main>
</AppWrap>
</ConnectedRouter>
</Provider>
내부 App.componentWillMount에서 Redux 작업 this.props.requestApplesApiData
이 트리거됩니다. 이는 사가 (apache)에서 데이터를 가져오고 감속기가 redux 상태에 추가 한 페이로드가있는 receiveApplesApiData
액션을 반환합니다.부모에서 saga가 완료 될 때까지 하위 구성 요소 렌더링 지연 종속 구성 요소
componentWillMount(){
// triggers an action
// which is picked up by a saga,
// which is handled by the reducer
// which updates the redux state
this.props.requestApplesApiData();
}
내가 (. REDUX 연장 승) 크롬 개발 도구에 검사 할 때
돌아 오는 상태는 괜찮 업데이트됩니다,하지만 난 REDUX 상태 (최근에 가져온 "사과"포함)으로 업데이트되지 않은 것으로 나타났습니다 Component2에서 경쟁 조건이 획득되는 동안, Component2에서 "apples"를 표시 할 수 없다는 것을 의미합니다. 즉, 렌더링 기능을 수행 할 당시 존재하지 않았기 때문입니다.
구조가 중첩 된 구조 인 경우 재 렌더링이 일반적으로 자동으로 수행되지만 "사과"는 redux 저장소의 자체 루트 개체에 있습니다.
어떻게하면 App1이 필요한 데이터를 가져올 지 Component1과 Component2가 기다릴 수 있습니까? 또는 다른 말로하면, 데이터가 희박해질 때까지 어떻게 App에서 렌더링 기능을 지연/연기 할 수 있습니까?