2016-09-07 81 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 decorator/ES6的正常實現。

我不知道爲什麼來自商店的數據沒有正確分發。任何幫助都比歡迎!

回答

0

我想通了。其中向下傳遞的狀態,但不是道具

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

:爲什麼道具不向下傳遞到childeren由於以下原因:

我用這個初始化的孩子。因此用this.props替換this.state爲我工作。