Skip to content

Commit

Permalink
Clarify usage of connect in README.md (#2845)
Browse files Browse the repository at this point in the history
Added a quick example of how to use `connect` in `react-redux` as there are no examples in this example.
  • Loading branch information
mrwillis authored and timneutkens committed Aug 27, 2017
1 parent 75a43f5 commit b543795
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion examples/with-apollo-and-redux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@ now
```

## The idea behind the example
By default, Apollo Client creates its own internal Redux store to manage queries and their results. If you are already using Redux for the rest of your app, [you can have the client integrate with your existing store instead](http://dev.apollodata.com/react/redux.html). This example is identical to the [`with-apollo`](https://github.com/zeit/next.js/tree/master/examples/with-apollo) with the exception of this Redux store integration.
By default, Apollo Client creates its own internal Redux store to manage queries and their results. If you are already using Redux for the rest of your app, [you can have the client integrate with your existing store instead](http://dev.apollodata.com/react/redux.html), which is what this example does. This example is identical to the [`with-apollo`](https://github.com/zeit/next.js/tree/master/examples/with-apollo) with the exception of this Redux store integration.

Note that you can acesss the redux store like you normally would using `react-redux`'s `connect` as per [here](http://dev.apollodata.com/react/redux.html#using-connect). Here's a quick example:

```js
const mapStateToProps = state => ({
location: state.form.location,
});

export default withData(connect(mapStateToProps, null)(Index));
```

`connect` must go inside `withData` otherwise `connect` will not be able to find the store.

0 comments on commit b543795

Please sign in to comment.