鍍金池/ 問答/HTML/ react-saga不起作用?。?/span>

react-saga不起作用???

react-saga中文文檔中的例子

sagas.js
export function* helloSaga() {
console.log('Hello Sagas!');
}

main.js
import "babel-polyfill"

import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import {helloSaga} from './sagas'

import Counter from './Counter'
import reducer from './reducers'

const store = createStore(
reducer,
applyMiddleware(createSagaMiddleware(helloSaga))
)

const action = type => store.dispatch({type})

function render() {
ReactDOM.render(

<Counter
  value={store.getState()}
  onIncrement={() => action('INCREMENT')}
  onDecrement={() => action('DECREMENT')} />,
document.getElementById('root')

)
}

render()
store.subscribe(render)

reducer.js
export default function counter(state = 0, action) {
switch (action.type) {

case 'INCREMENT':
  return state + 1
case 'INCREMENT_IF_ODD':
  return (state % 2 !== 0) ? state + 1 : state
case 'DECREMENT':
  return state - 1
default:
  return state

}
}

回答
編輯回答
拮據(jù)

首先名字是 redux-saga 它是 redux 的一個中間件

其次中文的文檔已經(jīng)很老了.你可以選擇看 英文文檔, 實在吃力的話可以對照的中文文檔看,

2018年5月14日 08:36