将 redux 与 aws-appsync 集成
Integrating redux with aws-appsync
有什么方法可以在react-native 中将redux 与aws-appsync 集成在一起吗?
如果有的话,你能给我提示或线索吗?我很难整合它。先感谢您。
我认为您应该能够连接您自己的 redux 商店,如他们的文档中所述。基本上创建您自己的并使用 react-redux
中的 connect(mapStateToProps, mapDispatchToProps)
来连接您的组件。
const MyComponent = props => <h1>HI!</h1>
const ReduxConnected = connect(mapStateToProps, mapDispatchToProps)(MyComponent)
const GraphQLConnected = graphql(gql`query { hi }`)(ReduxConnected)
然后在你的应用程序的根目录下有
import AWSAppSyncClient from "aws-appsync";
import { Provider as ReduxProvider } from 'react-redux'
import { graphql, ApolloProvider } from 'react-apollo';
import { Rehydrated } from 'aws-appsync-react';
import { createStore } from 'redux'
const client = new AWSAppSyncClient({...})
const store = createStore({...})
const ConnectedApp = () =>
<ApolloProvider client={client}>
<Rehydrated>
<ReduxProvider store={store}>
<App />
</ReduxProvider>
</Rehydrated>
</ApolloProvider>
我还没有机会尝试这个设置,但我很快就会用任何发现进行编辑。与此同时,link 展示了如何使用 MobX 而不是 Redux (https://github.com/dabit3/heard) 的 AppSync 构建完整的 RN 应用程序,这也是一个不错的起点。
有什么方法可以在react-native 中将redux 与aws-appsync 集成在一起吗? 如果有的话,你能给我提示或线索吗?我很难整合它。先感谢您。
我认为您应该能够连接您自己的 redux 商店,如他们的文档中所述。基本上创建您自己的并使用 react-redux
中的 connect(mapStateToProps, mapDispatchToProps)
来连接您的组件。
const MyComponent = props => <h1>HI!</h1>
const ReduxConnected = connect(mapStateToProps, mapDispatchToProps)(MyComponent)
const GraphQLConnected = graphql(gql`query { hi }`)(ReduxConnected)
然后在你的应用程序的根目录下有
import AWSAppSyncClient from "aws-appsync";
import { Provider as ReduxProvider } from 'react-redux'
import { graphql, ApolloProvider } from 'react-apollo';
import { Rehydrated } from 'aws-appsync-react';
import { createStore } from 'redux'
const client = new AWSAppSyncClient({...})
const store = createStore({...})
const ConnectedApp = () =>
<ApolloProvider client={client}>
<Rehydrated>
<ReduxProvider store={store}>
<App />
</ReduxProvider>
</Rehydrated>
</ApolloProvider>
我还没有机会尝试这个设置,但我很快就会用任何发现进行编辑。与此同时,link 展示了如何使用 MobX 而不是 Redux (https://github.com/dabit3/heard) 的 AppSync 构建完整的 RN 应用程序,这也是一个不错的起点。