我正在尝试将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>
);
...