2017-08-02 129 views
0

我在构造函数this.state = {};中设置了状态,但是参数在calculateState方法中为空。我应该在哪里设置容器的初始状态?为什么在Flux的calculateState方法中prevState参数为null?

class QuestionnairesContainer extends Component { 
    static getStores() { 
    return [QuestionnairesStore]; 
    } 

    static calculateState(prevState) { 
    return { 
     questionnairesList: QuestionnairesStore.getState().questionnairesList, 
     pagingObject: prevState.pagingObject 
    }; 
    } 

    constructor(props) { 
    super(props); 
    this.state = { 
     pagingObject: someData 
    }; 
    } 

    render() { 
    return (
     <section> 
     </section> 
    ); 
    } 
} 

export default Container.create(QuestionnairesContainer); 

回答

0

我找到了焊剂GitHub的解决方案。

static calculateState(prevState) { 
    const init = prevState ? {} : { 
     pagingObject: someData, 
    }; 
    return { 
     ...init, 
     questionnairesList: QuestionnairesStore.getState().questionnairesList 
    }; 
    } 
    constructor(props) { 
     super(props); 
    } 
相关问题