redux-saga / redux-saga-beginner-tutorial

Redux/Redux-saga beginner tutorial
MIT License
587 stars 543 forks source link

error in helloSaga tutorial #13

Open kissshot opened 8 years ago

kissshot commented 8 years ago

the tutorial :

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

cause a error : middleware.js:27Uncaught Error: You passed a function to the Saga middleware. You are likely trying to start a Saga by directly passing it to the middleware. This is no longer possible starting from 0.10.0. To run a Saga, you must do it dynamically AFTER mounting the middleware into the store.

so I change to:

const sagaMiddleware = createSagaMiddleware()
const store = createStore(
  reducer,
  applyMiddleware(sagaMiddleware)
)
sagaMiddleware.run(helloSaga)
raymond-cat commented 7 years ago

me to

raymond-cat commented 7 years ago

chang main.js code

const sagaMiddleware = createSagaMiddleware()

const store = createStore(
  reducer,
  applyMiddleware(sagaMiddleware)
)

sagaMiddleware.run(helloSaga)
ummahusla commented 7 years ago

@kissshot @durongzhang I think that you are missing const action = type => store.dispatch({type}) . It works fine for me.


Code

import "babel-polyfill"

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

import Counter from './Counter'
import reducer from './reducers'
import { helloSaga } from './sagas'

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

sagaMiddleware.run(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)

Output

Navigated to http://10.10.5.75:9966/
sagas.js:2 Hello Sagas!
lietu555 commented 7 years ago

me to

Chaos-M commented 7 years ago

thanks~