
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
next-redux-saga
Advanced tools
redux-saga HOC for Next.js
yarn add next-redux-saga
Check out the official Next.js example or clone this repository and run the local example.
yarn
yarn start
next-redux-saga
uses the redux store created by next-redux-wrapper. Please refer to their documentation for more information.
import {createStore, applyMiddleware} from 'redux'
import createSagaMiddleware from 'redux-saga'
import rootReducer from './root-reducer'
import rootSaga from './root-saga'
const sagaMiddleware = createSagaMiddleware()
function configureStore(initialState) {
const store = createStore(
rootReducer,
initialState,
applyMiddleware(sagaMiddleware)
)
/**
* next-redux-saga depends on `runSagaTask` and `sagaTask` being attached to the store.
*
* `runSagaTask` is used to rerun the rootSaga on the client when in sync mode (default)
* `sagaTask` is used to await the rootSaga task before sending results to the client
*
*/
store.runSagaTask = () => {
store.sagaTask = sagaMiddleware.run(rootSaga)
}
// run the rootSaga initially
store.runSagaTask()
return store
}
export default configureStore
import React, {Component} from 'react'
import withRedux from 'next-redux-wrapper'
import withReduxSaga from 'next-redux-saga'
import configureStore from './configure-store'
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 withRedux(configureStore, state => state)(
withReduxSaga(ExamplePage)
)
To be consistent with how Next.js works, next-redux-saga
defaults to sync mode in version 2.x. When you trigger a route change on the client, your browser WILL NOT navigate to the new page until getInitialProps()
has completed running all it's asynchronous tasks.
For backwards compatibility with 1.x, async mode is still supported, however it is no longer the default behavior. When you trigger a route change on the client in async mode, your browser WILL navigate to the new page immediately and continue to carry out the asynchronous tasks from getInitialProps()
. When the asynchronous tasks have completed, React will rerender the components necessary to display the async data.
// sync mode
withReduxSaga(ExamplePage)
// async mode
withReduxSaga({async: true})(ExamplePage)
![]() | ![]() |
---|---|
Brent Mealhouse | Artem Abzanov |
yarn
yarn link
yarn test --watch
and start making your changesyarn link next-redux-saga
to test your changes in an actual projectMIT
FAQs
redux-saga HOC for Next.js
The npm package next-redux-saga receives a total of 4,114 weekly downloads. As such, next-redux-saga popularity was classified as popular.
We found that next-redux-saga demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.