Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么';我的红魔传奇有什么问题吗_Javascript_Reactjs_React Native_Redux_Redux Saga - Fatal编程技术网

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);