2016-08-31 15 views
0

データを別のコンポーネントに渡すことも、コンポーネントから関数にアクセスして別のコンポーネントで関数を実行することもありません。コンポーネントAはデータベースからデータを取り込みます。コンポーネントBは、データベース内の一部のデータを編集します。私はコンポーネントBのいくつかのデータを編集するとき、私は再実行するコンポーネントAの関数(フェッチデータ)が必要です。コンポーネントAのリストを更新する必要があります。React Native:別のコンポーネントのコンポーネントで関数を実行する


私はタブバーを持っています.1つのタブはデータをリストし、他のタブはデータを編集できます。私はデータを編集した後、最初のタブに行くと、まだ古いデータが表示されます。 タブを選択するたびにタブを再読み込みする方法があります。

私はreact-native-router-fluxを使用していますが、私はまだそれに慣れていません。

可能ですか?任意のソリューションをしてください?

答えて

0

解決策が見つかりました。 コンポーネントがほとんどありません。成分A、BおよびC実際に各成分が(IOSのTabBarの)タブで

ユーザはコンポーネントCにいくつかの変更を行うたびに、ユーザー、iは、成分C中の成分AおよびB

を更新する必要があります変更を行い、私はこのようなActions.refresh呼んでいる:

/// Component C 
 
updated(){ 
 
    //// Update database 
 
    Actions.componentA(); 
 
    Actions.refresh({somekey: 'True'}); 
 
    Actions.componentB(); 
 
    Actions.refresh({somekey: 'True'}); 
 
    Actions.componentC(); 
 
    Actions.refresh({somekey: 'True'}); 
 
} 
 
/// So i first call Actions.componentA then i call Actions.refresh to send some props to each component. 
 

 
/// in each component i added componentwillreceive update. when it receives new props, i'm calling the fetch function again. and setting some random state to make the component reload. 
 

 
componentWillReceiveProps() { 
 
     this.fetchData(); 
 
     this.setState({ 
 
     somekey: 'yes' 
 
     }); 
 
    }

関連する問題