2016-05-05 15 views
0
I am new to ReactJS and baobab. Here is what I have: 

CODEのSTART:ReacJS、カーソルを解放する方法をコンポーネントのマウントが解除された後

var stateTree = new Baobab({ 
    outputs: { 
    campaignList: [], 
    exportFields: [], 
    exports: [], 
    hygiene: [], 
    exportFormatList: [] 
    } 
}); 

var CampaignEdit = React.createClass({ 
    mixins: [ 
    stateTree.mixin, 
    React.addons.LinkedStateMixin, 
    SelectDropdownMixin, 
    Router.State 
    ], 
    cursors: { 
    campaignList: ['outputs','campaignList'], 
    exports: ['outputs', 'exports'] 
    }, 

    componentDidMount: function() { 
    this.cursors.campaignList.on('update', this.updateCampaignState); 
    this.cursors.accountList.on('update', this.updateAccountState); 
    }, 

    updateAccountState: function() { 
    var accountList = deref_cursor(this.cursors.accountList, []); 
    var select_options = this.state.select_options; 
    for (var i=0; i<accountList.length; i++) { 
     var account = accountList[i]; 
     select_options['owner_id'][account.id] = account.firstname + ' ' + account.lastname; 
    } 
    this.setState({ 'select_options': select_options}); 
    }, 

    render: function() { 
    /* render the component here */ 
    } 

}); 

しかしCODEのENDユーザーが別のコンポーネントに切り替えると、このコンポーネントに戻ってくるよう私はこのエラーが発生します: "キャッチされていないエラー:不変違反:replaceState(...):マウントされているコンポーネントまたはマウントされているコンポーネントのみを更新できます。

This is coming up as my current component being loaded is in "UNMOUNTED" state. 

My questions is that if the component is already unmounted, why is the unmounted component being reused? Is there a way to avoid this? 

答えて

0

カーソルを使用してイベントが発生したために問題が見つかりました。 componentWillUnmountを追加し、更新イベントのバインドを解除しました。

関連する問題