next redux saga
ver side rendering (SSR)
Because next.js has grown massively and other packages with better support have covered the redux-saga SSR functionality.
See #79 for more information.
redux-sagaHOC for Next.js. controlledredux-sagaexecution for server side rendering.
Attention: Synchronous HOC is no longer supported since version 4.0.0!
yarn add next-redux-sagaCheck out the official Next.js example or clone this repository and run the local example.
yarnyarn startnext-redux-saga uses the redux store created by next-redux-wrapper. Please refer to their documentation for more information.
import {applyMiddleware, createStore} from 'redux'
import createSagaMiddleware from 'redux-saga'
import {createWrapper} from 'next-redux-wrapper'
import rootReducer from './root-reducer'
import rootSaga from './root-saga'
const makeStore = context => {
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
rootReducer,
applyMiddleware(sagaMiddleware),
)
store.sagaTask = sagaMiddleware.run(rootSaga)
return store
}
const wrapper = createWrapper(makeStore)
export default wrapper_app.js Componentimport React from 'react'
import App from 'next/app'
import withReduxSaga from 'next-redux-saga'
import wrapper from './store-wrapper'
class ExampleApp extends App {
static async getInitialProps({Component, ctx}) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
return {pageProps}
}
render() {
const {Component, pageProps} = this.props
return (
<Component {...pageProps} />
)
}
}
export default wrapper.withRedux(withReduxSaga(ExampleApp))import React, {Component} from 'react'
import {connect} from 'react-redux'
class ExamplePage extends Component {
static async getInitialProps({store}) {
store.dispatch({type: 'SOME_ASYNC_ACTION_REQUEST'})
return {staticData: 'Hello world!'}
}
render() {
return <div>{this.props.staticData}</div>
}
}
export default connect(state => state)(ExamplePage)Brent Mealhouse | Timon Borter | Artem Abzanov | Robbin Habermehl |
yarnyarn linkyarn test --watch and start making your changesyarn link next-redux-saga to test your changes in an actual projectThis project is licensed under the terms of MIT license. See the license file for more information.