興味深い問題の種類...redux古い状態を接続する
私はすべての状態を取得するために接続するコンポーネントのセットを持っています。これらのコンポーネントは、しばしばお互いの子供、時には深く入れ子の子供です。
状態が変更された場合にのみshouldComponentUpdateにこれらのコンポーネントを追加します。そうでない場合はfalseを返します。状態は不変のマップです。私はis(...)を使って平等を検証します。問題は、状態が変更されたときに、その一部が変更を参照し、一部が古い状態になって変更が見られないように見えることです。状態を変更する別のアクションを完了すると、前の状態が表示されますが、最新の状態は表示されません。
アイデア?ここにミドルウェアはありません。
*編集...コード。作品の多くはここにありますので、
function checkNewState(nextProps, instance){
return !is(nextProps.state.reducerName, instance.props.state.reducerName)
}
const StupidParent = React.createClass({
shouldComponentUpdate: function(nextProps){
return checkNewState(nextProps, instance)
},
render: function(){
return <p>{this.props.state.reducerName.get('name')}
{this.props.replace(this)}
</p>
}
})
const StupidChild = React.createClass({
shouldComponentUpdate: function(nextProps){
return checkNewState(nextProps, instance);
},
render: function(){
return <p onClick={changeStateNameProperty}>
{this.props.state.reducerName.get('name')}
</p>
}
})
function mapStateToProps(state){
return {state}
}
export const Parent = connect(mapStateToProps)(StupidParent);
export const Child = connect(mapStateToProps)(StupidChild);
<Parent replace={(parent)=>{
return <Child />
}} />
コードなしでは、お手伝いができません。 – whitep4nther
コードコードコード。 –
私はそれを理解しました。私のコードは状態に依存していると思っていましたが、私のコードも(州によって生成されたものですが、shouldComponentUpdateをトリガーしない状態が更新された後にのみ生成されます)GAH – l2silver