Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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
Reactjs 使用redux saga时,参数不会从组件传递到操作_Reactjs_React Redux_Redux Saga - Fatal编程技术网

Reactjs 使用redux saga时,参数不会从组件传递到操作

Reactjs 使用redux saga时,参数不会从组件传递到操作,reactjs,react-redux,redux-saga,Reactjs,React Redux,Redux Saga,我正在使用Redux saga,以便可以从API端获取项目。我已经按照中给出的说明在索引页中初始化了我的saga中间件 下面的代码片段是我的/src/index.js import React from 'react'; import ReactDOM from 'react-dom'; import { createStore, applyMiddleware } from 'redux'; import { Provider } from 'react-redux'; import crea

我正在使用Redux saga,以便可以从API端获取项目。我已经按照中给出的说明在索引页中初始化了我的saga中间件

下面的代码片段是我的
/src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import createSagaMiddleware from 'redux-saga';
import reducer from './reducers';
import App from './root-components/app';

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

ReactDOM.render(
  <Provider store={store}>
    <div>
      <App />
    </div>
  </Provider>,
  document.getElementById('root')
);
我正在调用action
fetchPrescriptionsFromUrl(res)
传递参数
res
。我的动作是
preaction
is

import {call, put} from "redux-saga/effects";
import  axios from 'axios';

const getCharacters = (accessPoint) => {
  axios.get(accessPoint)
}

export function *fetchPrescriptionsFromUrl(accessToken){
  console.log('AT', accessToken)
  try {
    const response = yield call(getCharacters(accessToken))
  } catch (e) {
    console.log(e)
  }
}
控制台上,从组件
索引传递的参数的log
。jsx
表示为
未定义的


我是
redux传奇的初学者
,不知道我在哪里出错。如果我能为这个问题找到任何解决方案,这将非常有用。

Redux Saga调用函数不能以这种方式使用。应该是这样的

const response = yield call(getCharacters, accessToken)
在您的案例中,
getCharacters
被立即评估,其结果被传递到
call


此外,您不应该在索引组件中使用sagaMiddleWare。(不仅仅是saga)中间件的要点是,您可以像平常一样发送操作,然后在中间件中捕获具体操作

感谢您编辑@marc_-ssen,how to pass
accessToken
Sir。还有别的办法吗。或者还有其他的例子吗?
const response = yield call(getCharacters, accessToken)