2016-11-21 1 views
3

変数を設定しようとすると、コンポーネントはフェッチが完了した後にのみ更新されます。ここにexapmleコードがあります。リアクションリレーpendingVariablesは常にsetVariablesの後でnullです

class RelayExample extends React.Component { 
    setVars() { 
    this.props.relay.setVariables({id: '2'}); 
    }; 
    render() { 
    console.log(this.props.relay.pendingVariables); 
    return (
     <div> 
     <button onClick={this.setVars.bind(this)}>set variable</button> 
     </div> 
    ); 
    } 
} 

RelayExample = Relay.createContainer(RelayExample, { 
    initialVariables: { 
    id: '1' 
    }, 
    fragments: { 
    userStore:()=> { 
     return Relay.QL` 
     fragment on userStore { 
     user(id:$id){ 
      email 
     } 
     } 
     `; 
    } 
    } 
}); 

ReactDOM.render(
    <Relay.RootContainer Component={RelayExample} route={new TestQuery()}/>, 
    document.getElementById('app') 
); 

私はコンソールでこの結果を得るボタン押す:私は右setVariables関数の後forceUpdateを使用する場合でも、私は同様の結果を得る enter image description here

を。

setVars() { 
     this.props.relay.setVariables({id: '2'}); 
     this.forceUpdate(); 
}; 

enter image description here

+0

環境はRelay.Store –

答えて

-1

私は、これは意図した動作であると信じています。 this.props.relay.setVariables()または this.props.relay.forceFetch()が呼び出されている場合

pendingVariables新しい小道具をフェッチ するために使用されている変数のセットが含まれ、すなわち、対応しますリクエスト が飛行中です。

飛行中のリクエストがない場合、pendingVariablesはnullです。

変数を設定した直後にコンソールログを表示する場合は、pendingVariablesに表示されます。

+0

です。[this](https://facebook.github.io/relay/docs/api-reference-relay-container.html#pendingvariables)の例によると間違っていない場合は、コンポーネントはsetVariablesとpendingVariablesの後に更新する必要があります。 –

+1

これは意図した動作ではありません。ここでも同じ問題があります。 – whitep4nther

関連する問題