next redux saga
ver side rendering (SSR)
لأن next.js قد نمت بشكل كبير وغيرها من الحزم بدعم أفضل قد غطت وظيفة redux-saga SSR. انظر #79 لمزيد من المعلومات.
redux-sagaHoc لـ Next.js. تنفيذredux-sagaالذي يتم التحكم فيه لتقديم جانب الخادم.
الانتباه: لم يعد المخصص المتزامن مدعومًا منذ الإصدار 4.0.0!
yarn add next-redux-sagaتحقق من مثال Next.js الرسمي أو استنساخ هذا المستودع وقم بتشغيل المثال المحلي.
yarnyarn start يستخدم next-redux-saga متجر Redux الذي تم إنشاؤه بواسطة Redux-Wrapper. يرجى الرجوع إلى وثائقهم لمزيد من المعلومات.
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 ) برنت وجبة | تيمون بيرتر | أرتيم أبزانوف | روبن هابرميل |
yarnyarn linkyarn test --watch وابدأ في إجراء تغييراتكyarn link next-redux-saga لاختبار تغييراتك في مشروع فعلي هذا المشروع مرخص بموجب شروط ترخيص معهد ماساتشوستس للتكنولوجيا. انظر ملف الترخيص لمزيد من المعلومات.