next-redux-saga
redux-saga HOC for Next.js
Attention: Synchronous HOC is no longer supported since version 4.0.0!
Installation
yarn add next-redux-saga
Getting Started
Check out the official Next.js example or clone this repository and run the local example.
Try the local example
- Clone this repository
- Install dependencies:
yarn
- Start the project:
yarn start
- Open http://localhost:3000
Usage
next-redux-saga
uses the redux store created by next-redux-wrapper. Please refer to their documentation for more information.
Configure Store
{ /** * Recreate the stdChannel (saga middleware) with every context. */ const sagaMiddleware = /** * Since Next.js does server-side rendering, you are REQUIRED to pass * `preloadedState` when creating the store. */ const store = /** * next-redux-saga depends on `sagaTask` being attached to the store during `getInitialProps`. * It is used to await the rootSaga task before sending results to the client. * However, next-redux-wrapper creates two server-side stores per request: * One before `getInitialProps` and one before SSR (see issue #62 for details). * On the server side, we run rootSaga during `getInitialProps` only: */ if req || !isServer storesagaTask = sagaMiddleware return store}
_app.js
Component
Configure Custom static async { let pageProps = {} if ComponentgetInitialProps pageProps = await Component return pageProps } { const Component pageProps store = thisprops return <Container> <Provider store=store> <Component ...pageProps /> </Provider> </Container> } configureStore
Connect Page Components
static async { store return staticData: 'Hello world!' } { return <div>thispropsstaticData</div> } stateExamplePage
Contributors
Brent Mealhouse 💻 ⚠️ 📖 🚧 💬 | Timon Borter 💻 ⚠️ 📖 🚧 💬 | Artem Abzanov 💻 ⚠️ 📖 | Robbin Habermehl 💻 ⚠️ 📖 |
Contributing
- Fork this repository to your own GitHub account and then clone it to your local device
- Install the dependecies:
yarn
- Link the package to the global module directory:
yarn link
- Run
yarn test --watch
and start making your changes - You can use
yarn link next-redux-saga
to test your changes in an actual project
LICENSE
This project is licensed under the terms of MIT license. See the license file for more information.