Javascript 什么';我的红魔传奇有什么问题吗
我创建了一个本地应用程序。我的Javascript 什么';我的红魔传奇有什么问题吗,javascript,reactjs,react-native,redux,redux-saga,Javascript,Reactjs,React Native,Redux,Redux Saga,我创建了一个本地应用程序。我的index.ios.js在这里我向商店添加了中间件 import React, { Component } from 'react' import { AppRegistry, } from 'react-native' import { Provider } from 'react-redux' import { applyMiddleware, createStore } from 'redux' import createLogger from 'redu
index.ios.js
在这里我向商店添加了中间件
import React, { Component } from 'react'
import {
AppRegistry,
} from 'react-native'
import { Provider } from 'react-redux'
import { applyMiddleware, createStore } from 'redux'
import createLogger from 'redux-logger'
import createSagaMiddleware from 'redux-saga'
import reducer from './src/reducers'
import * as sagas from './src/sagas'
import Scene from './src/components/scene'
const store = createStore(
reducer,
applyMiddleware(createSagaMiddleware(...sagas), createLogger())
);
const CitiesApp = () => (
<Provider store={store}>
<Scene />
</Provider>
);
AppRegistry.registerComponent('CitiesApp', () => CitiesApp);
我从组件中的componentDidMount
调用它
componentDidMount() {
this.props.dispatch(fetchUser());
console.log('componentDidMount')
}
我还有一个传奇故事:
export function* watchUserFetch() {
console.log('watchUserFetch');
yield take(actions.USER_FETCH_REQUESTED);
yield fork(fetchUser);
}
function* fetchUser() {
try {
const user = yield call(() => Api.fetchUser());
yield put({type: actions.USER_FETCH_SUCCEEDED, user});
} catch (e) {
yield put({type: actions.USER_FETCH_FAILED, message: e.message});
}
}
但这一传奇并不奏效。我没有在控制台中看到watchUserFetch
,并且fetchUser
函数没有运行
我的错在哪里?为什么fetchUser
不运行
export default function* rootSaga() {
yield [
watchUserFetch()
]
}
import createSagaMiddleware from 'redux-saga';
import rootSaga from './sagas.js';
const sagaMiddle= createSagaMiddleware();
const store = createStore(reducer,
applyMiddleware(sagaMiddle,createLogger())
);
sagaMiddle.run(rootSaga);
import createSagaMiddleware from 'redux-saga';
import rootSaga from './sagas.js';
const sagaMiddle= createSagaMiddleware();
const store = createStore(reducer,
applyMiddleware(sagaMiddle,createLogger())
);
sagaMiddle.run(rootSaga);