Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
next-redux-saga
Advanced tools
redux-saga HOC for Next.js
Attention: Synchronous HOC is no longer supported since version 4.0.0!
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'
function configureStore(preloadedState, {isServer, req = null}) {
/**
* Recreate the stdChannel (saga middleware) with every context.
*/
const sagaMiddleware = createSagaMiddleware()
/**
* Since Next.js does server-side rendering, you are REQUIRED to pass
* `preloadedState` when creating the store.
*/
const store = createStore(
rootReducer,
preloadedState,
applyMiddleware(sagaMiddleware)
)
/**
* 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) {
store.sagaTask = sagaMiddleware.run(rootSaga)
}
return store
}
export default configureStore
_app.js
Componentimport React from 'react'
import {Provider} from 'react-redux'
import App, {Container} from 'next/app'
import withRedux from 'next-redux-wrapper'
import withReduxSaga from 'next-redux-saga'
import configureStore from './configure-store'
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, store} = this.props
return (
<Container>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</Container>
)
}
}
export default withRedux(configureStore)(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 💻 ⚠️ 📖 |
yarn
yarn link
yarn 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.
FAQs
redux-saga HOC for Next.js
The npm package next-redux-saga receives a total of 5,372 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.