I'm trying redux-saga
.
I expected console.log("Now Called saga03!!");
executed, after I dispatch event by clicking button.
import { fork, take } from 'redux-saga/effects';
export function* helloSaga(){
console.log('Hello Saga Root !!');
yield fork(saga01);
yield fork(saga02);
yield fork(sagaFetch);
}
function* saga01() {
console.log('Hello Saga01 !!!');
}
function* saga02() {
console.log('Hello Saga02 !!!');
}
function* sagaFetch() {
while (true){
console.log("Loop Start!!");
yield take('FETCH_SAGA_START');
console.log("Now Called saga03!!");
}
}
import { createBrowserHistory } from 'history';
import { applyMiddleware, compose, createStore} from 'redux';
import { routerMiddleware } from 'connected-react-router';
import createSagaMiddleware from 'redux-saga';
import rootReducer from "../reducers";
import { helloSaga } from "../sagas/saga";
const sagaMiddleware = createSagaMiddleware();
export const history = createBrowserHistory()
export default function configureStore() {
const store = createStore(
rootReducer(history), // Reducers
compose(
process.env.NODE_ENV === 'development' && window.devToolsExtension ? window.devToolsExtension() : f => f,
applyMiddleware(
routerMiddleware(history),
sagaMiddleware
) // Middle Wares
)
);
sagaMiddleware.run(helloSaga);
return store;
}
class Sample extends Component{
constructor(props) {
super(props);
this.state = {
data: []
}
this.doCall = this.doCall.bind(this);
}
doCall(){
console.log("DO CALL!!");
this.props.dispatch({type: 'FETCH_SAGA_START'});
}
render() {
return (
<div>
<button onClick={this.doCall}>Call Saga 03</ button>
</div>
);
}
export default connect((state)=>state)(Sample);
However I can not see any console.log executed.
Am I misunderstanding?