next redux saga
ver side rendering (SSR)
เพราะ next.js ได้เติบโตอย่างหนาแน่นและแพ็คเกจอื่น ๆ ที่มีการสนับสนุนที่ดีกว่าได้ครอบคลุมฟังก์ชันการทำงานของ redux-saga SSR ดู #79 สำหรับข้อมูลเพิ่มเติม
redux-sagahoc สำหรับ next.js ควบคุมการดำเนินการredux-sagaสำหรับการแสดงผลด้านเซิร์ฟเวอร์
ความสนใจ: ไม่รองรับ Synchronous Hoc อีกต่อไปตั้งแต่เวอร์ชัน 4.0.0!
yarn add next-redux-sagaตรวจสอบตัวอย่างอย่างเป็นทางการ next.js หรือโคลนที่เก็บนี้และเรียกใช้ตัวอย่างท้องถิ่น
yarnyarn start next-redux-saga ใช้ Redux Store ที่สร้างขึ้นโดย Next-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 ) Brent Mealhouse | Timon Borter | Artem Abzanov | Robbin Habermehl |
yarnyarn linkyarn test --watch และเริ่มทำการเปลี่ยนแปลงของคุณyarn link next-redux-saga เพื่อทดสอบการเปลี่ยนแปลงของคุณในโครงการจริง โครงการนี้ได้รับใบอนุญาตภายใต้ข้อกำหนดของใบอนุญาต MIT ดูไฟล์ใบอนุญาตสำหรับข้อมูลเพิ่มเติม