rsnext/examples/with-apollo-and-redux-saga
Shu Uesugi c57cdbb31d
Rename zeit.co/new → zeit.co/import (#10674)
* Replace zeit.co/new → zeit.co/import

* Update deployment.md
2020-02-24 19:08:34 -05:00
..
components Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
lib Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
pages Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
package.json with apollo and redux saga example: Update deps (#6734) 2019-03-27 16:00:57 -05:00
README.md Rename zeit.co/new → zeit.co/import (#10674) 2020-02-24 19:08:34 -05:00
routes.js Add prettier for examples directory (#5909) 2018-12-17 17:34:32 +01:00
server.js Add prettier for examples directory (#5909) 2018-12-17 17:34:32 +01:00

Apollo & Redux Saga Example

In 2.0.0, Apollo Client severs out-of-the-box support for redux in favor of Apollo's client side state management. This example aims to be an amalgamation of the with-apollo and with-redux-saga examples.

How to use

Using create-next-app

Execute create-next-app with npm or Yarn to bootstrap the example:

npm init next-app --example with-apollo-and-redux-saga with-apollo-and-redux-saga-app
# or
yarn create next-app --example with-apollo-and-redux-saga with-apollo-and-redux-saga-app

Download manually

Download the example:

curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-apollo-and-redux-saga
cd with-apollo-and-redux-saga

Install it and run:

npm install
npm run dev
# or
yarn
yarn dev

Deploy it to the cloud with ZEIT Now (Documentation).

Note:

Note that you can access the redux store like you normally would using react-redux's connect. Here's a quick example:

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

export default withReduxSaga(connect(mapStateToProps, null)(Index))

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

In these with-apollo examples, the withData() HOC must wrap a top-level component from within the pages directory. Wrapping a child component with the HOC will result in a Warning: Failed prop type: The prop 'serverState' is marked as required in 'WithData(Apollo(Component))', but its value is 'undefined' error. Down-tree child components will have access to Apollo, and can be wrapped with any other sort of graphql(), compose(), etc HOC's.