redux-saga-beginner-tutorial icon indicating copy to clipboard operation
redux-saga-beginner-tutorial copied to clipboard

error in helloSaga tutorial

Open kissshot opened this issue 8 years ago • 5 comments

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)

kissshot avatar Nov 16 '16 06:11 kissshot

me to

raymond-cat avatar Nov 30 '16 10:11 raymond-cat

chang main.js code

const sagaMiddleware = createSagaMiddleware()

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

sagaMiddleware.run(helloSaga)

raymond-cat avatar Dec 01 '16 04:12 raymond-cat

@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!

ummahusla avatar Dec 20 '16 10:12 ummahusla

me to

lietu555 avatar Mar 30 '17 12:03 lietu555

thanks~

Chaos-M avatar Aug 15 '17 05:08 Chaos-M