如何同时使用react-apollo和react-router-native

时间:2019-03-20 18:12:51

标签: reactjs react-native react-router graphql apollo

我正在尝试将react-router-native添加到我的react-native / react-apollo应用程序中,但是当<Query>标签将数据返回给客户端时,该组件不会再次呈现(总是显示<Loading/>标签)。我做错了吗?

App.js

...

render() {
  const { isLoggedIn, token, hp } = this.state;
  if (!isLoggedIn) {
    return <Login onLogin={this.handleLogin} />;
  } else {
    return (
      <NativeRouter>
        <ApolloProvider client={CreateApolloClient(token)}>
          <Switch>
           <Route path="/" component={Home}/>
          </Switch>
        </ApolloProvider>
      </NativeRouter>
    );
  }
}

...

Home.js

...

<Query query={getHomeData}>
 {({ loading, error, data: { getHomeData: data } }) => {
   return loading ? ( <Loading /> ) : (
      <ScrollView style={style.dataContainer}>
         <Text>{JSON.stringify(data)}</Text>
      </ScrollView>
    );
  }}
</Query>

...

Loading.js

...

return (
  <View>
    <Text>LOADING CONTENT...</Text>
  </View>
);

...

0 个答案:

没有答案