2016-09-07 2 views
1

데이터를 제공하고 상태 변경에 반응하기 위해 실제 매장에 내 ​​매장을 연결하려고합니다. 슬프게도 상점 연결에 결함이있는 것 같습니다.altjs 반응 저장 연결이 작동하지 않음

@connectToStores 
class App extends Component { 

    static getStores() { 
     return [CategoryStore, UserStore, LocalizationStore]; 
    } 

    static getPropsFromStores() { 
     return { 
      ...CategoryStore.getState(), 
      ...UserStore.getState(), 
      ...LocalizationStore.getState() 
    }; 
    } 

    static componentDidConnect(props, context) { 
     ca.fetchCategories(); 
     la.fetchLocales(); 
    } 

프로젝트를 실행할 때 componentDidConnect가 사용되지 않습니다. 이에 따르면 https://github.com/altjs/connect-to-stores/issues/6은 상점이 연결 되 자마자 기능이 실행되어야합니다. 부분적으로 작업을 componentWillMount에 넣는 작업을했지만 상태가 제대로 업데이트되지 않았습니다. 그래서 상점 연결이 제대로 설정되지 않았다고 생각합니다.

나는 또한 ES7 데코레이터/ES6 정상적인 구현을 시도했다.

상점의 데이터가 제대로 분배되지 않은 이유를 알지 못합니다. 어떤 도움이 환영보다 더!

답변

0

나는 그것을 알아 냈다. 소품 인해 다음에 childeren에 아래로 통과되지 않은 이유 :

내가 아이를 초기화하려면이 옵션을 사용 :

const children = React.Children.map(this.props.children, (child) => { 
    return React.cloneElement(child, this.state); 
}); 

상태가 아닌 소품을 전달합니다. 그러므로 this.props로 this.state를 대체하면 나를 위해 일했습니다.

관련 문제