diff --git a/examples/with-redux/README.md b/examples/with-redux/README.md index c8e60b897b..93a1b04021 100644 --- a/examples/with-redux/README.md +++ b/examples/with-redux/README.md @@ -31,11 +31,11 @@ In this example we are going to display a digital clock that updates every secon ![](http://i.imgur.com/JCxtWSj.gif) -Our page is located at `pages/index.js` so it will map the route `/`. To get the initial data for rendering we are implementing the static method `getInitialProps`, initializing the redux store and dispatching the required actions until we are ready to return the initial state to be rendered. +Our page is located at `pages/index.js` so it will map the route `/`. To get the initial data for rendering we are implementing the static method `getInitialProps`, initializing the redux store and dispatching the required actions until we are ready to return the initial state to be rendered. Since the component is wrapped with `next-react-wrapper`, the component is automatically connected to Redux and wrapped with `react-redux Provider`, that allows us to access redux state immediately and send the store down to children components so they can access to the state when required. -Connect every page to redux like you normally do using `nextConnect` function. `nextConnect` provides the same abilities of `connect`, in addition, it wraps every page with `react-redux Provider`. For safety it is recommended to wrap all pages, no matter if they use Redux or not, so that you should not care about it anymore in all child components. For normal components, you just need to use `connect` of `react-redux` instead of `nextConnect`. +For safety it is recommended to wrap all pages, no matter if they use Redux or not, so that you should not care about it anymore in all child components. -`nextConnect` is generated by `nextConnectRedux`, which accepts `makeStore` as first argument, all other arguments are internally passed to `react-redux connect()` function. `makeStore` function will receive initialState as one argument and should return a new instance of redux store each time when called, no memoization needed here. See the [full example](https://github.com/huzidaha/next-connect-redux) in the `next-connect-redux` repository. +`withRedux` function accepts `makeStore` as first argument, all other arguments are internally passed to `react-redux connect()` function. `makeStore` function will receive initialState as one argument and should return a new instance of redux store each time when called, no memoization needed here. See the [full example](https://github.com/kirill-konshin/next-redux-wrapper#usage) in the Next Redux Wrapper repository. To pass the initial state from the server to the client we pass it as a prop called `initialState` so then it's available when the client takes over. diff --git a/examples/with-redux/package.json b/examples/with-redux/package.json index 786266b682..6af311f24c 100644 --- a/examples/with-redux/package.json +++ b/examples/with-redux/package.json @@ -8,7 +8,7 @@ }, "dependencies": { "next": "^2.0.0-beta", - "next-connect-redux": "^0.1.1", + "next-redux-wrapper": "^1.0.0", "react": "^15.4.2", "react-dom": "^15.4.2", "react-redux": "^5.0.1", diff --git a/examples/with-redux/pages/index.js b/examples/with-redux/pages/index.js index e699e272d8..5408229f95 100644 --- a/examples/with-redux/pages/index.js +++ b/examples/with-redux/pages/index.js @@ -1,11 +1,11 @@ import React from 'react' -import { nextConnect, reducer, startClock, setPageTitle } from '../store' +import { reducer, initStore, startClock } from '../store' +import withRedux from 'next-redux-wrapper'; import Page from '../components/Page' class Counter extends React.Component { static getInitialProps ({ store, isServer }) { store.dispatch({ type: 'TICK', light: !isServer, ts: Date.now() }) - store.dispatch({ type: 'SET_PAGE_TITLE', title: 'Index Page' }) return { isServer } } @@ -19,9 +19,9 @@ class Counter extends React.Component { render () { return ( - + ) } } -export default nextConnect((state) => state)(Counter) +export default withRedux(initStore)(Counter) \ No newline at end of file diff --git a/examples/with-redux/pages/other.js b/examples/with-redux/pages/other.js index 234b784a68..459a657272 100644 --- a/examples/with-redux/pages/other.js +++ b/examples/with-redux/pages/other.js @@ -1,11 +1,11 @@ import React from 'react' -import { nextConnect, reducer, startClock, setPageTitle } from '../store' +import { reducer, initStore, startClock } from '../store' +import withRedux from 'next-redux-wrapper'; import Page from '../components/Page' class Counter extends React.Component { static getInitialProps ({ store, isServer }) { store.dispatch({ type: 'TICK', light: !isServer, ts: Date.now() }) - store.dispatch({ type: 'SET_PAGE_TITLE', title: 'Other Page' }) return { isServer } } @@ -19,9 +19,9 @@ class Counter extends React.Component { render () { return ( - + ) } } -export default nextConnect((state) => state)(Counter) +export default withRedux(initStore)(Counter) \ No newline at end of file diff --git a/examples/with-redux/store.js b/examples/with-redux/store.js index c695c375b1..a15a9f81ab 100644 --- a/examples/with-redux/store.js +++ b/examples/with-redux/store.js @@ -1,22 +1,13 @@ import { createStore, applyMiddleware } from 'redux' import thunkMiddleware from 'redux-thunk' -import nextConnectRedux from 'next-connect-redux' -export const reducer = (state = { lastUpdate: 0, light: false, title: '' }, action) => { +export const reducer = (state = { lastUpdate: 0, light: false }, action) => { switch (action.type) { - case 'TICK': return { lastUpdate: action.ts, light: !!action.light, title: state.title } - case 'SET_PAGE_TITLE': return { ...state, title: action.title } + case 'TICK': return { lastUpdate: action.ts, light: !!action.light } default: return state } } -export const setPageTitle = (title) => { - return { - type: 'SET_PAGE_TITLE', - title - } -} - export const startClock = () => dispatch => { return setInterval(() => dispatch({ type: 'TICK', light: true, ts: Date.now() }), 800) } @@ -24,5 +15,3 @@ export const startClock = () => dispatch => { export const initStore = (initialState) => { return createStore(reducer, initialState, applyMiddleware(thunkMiddleware)) } - -export const nextConnect = nextConnectRedux(initStore)