在reactjs中渲染之前重置状态

时间:2017-06-09 07:57:13

标签: reactjs meteor react-native

我正在使用与Meteor的反应,我的数据来自createContainer

export default createContainer((props) => {
const { search } = props.dataTables.favorites;
let data = [];

data = Meteor.user().favorites;

return { data };
}, StarredListView);

现在我想在状态初始化后对数据进行一些处理

constructor(props) {
    super(props);

    this.state = {
        data: props.data
    };

    this.resetOldData = this.resetOldData.bind(this);
}

现在我怎样才能确保在调用数据resetOldData之前调用并重置状态。我在哪里可以调用此函数来重置我的状态。

resetOldData() {
    Meteor.call('reset.old.favorite.data', (err, res) => {
        if (err) { this.props.renderAlert(err.reason, null, true); }
        if (res) {
            this.props.renderAlert(res.message);
            this.setState({ data: res });
        }
    });
}

1 个答案:

答案 0 :(得分:0)

您需要查看React生命周期文档:https://facebook.github.io/react/docs/react-component.html

在非常具体的地方,您需要回复进入的数据以及如何影响组件的状态。

对状态的某些更改仅属于组件生命周期中的特定位置。

相关问题