next redux saga
ver side rendering (SSR)
next.js 대규모로 성장했으며 더 나은 지원을 가진 다른 패키지는 redux-saga SSR 기능을 다루었습니다. 자세한 내용은 #79를 참조하십시오.
redux-sagahoc for next.js. 서버 측 렌더링을위한 제어 된redux-saga실행.
주의 : 버전 4.0.0 이후 동기식 HOC가 더 이상 지원되지 않습니다!
yarn add next-redux-saga공식 Next.js 예제를 확인 하거나이 저장소를 복제하고 로컬 예제를 실행하십시오.
yarnyarn start next-redux-saga Next-Redux-Wrapper가 만든 Redux 매장을 사용합니다. 자세한 내용은 문서를 참조하십시오.
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 구성 요소를 구성하십시오 import 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 ) 브렌트 식사 하우스 | 티몬 보터 | Artem Abzanov | Robbin Habehl |
yarnyarn link 에 연결합니다.yarn test --watch 시작하고 변경을 시작하십시오yarn link next-redux-saga 사용하여 실제 프로젝트의 변경 사항을 테스트 할 수 있습니다. 이 프로젝트는 MIT 라이센스 조건에 따라 라이센스가 부여됩니다. 자세한 내용은 라이센스 파일을 참조하십시오.