Reactjs 使用redux saga时,参数不会从组件传递到操作
我正在使用Redux saga,以便可以从API端获取项目。我已经按照中给出的说明在索引页中初始化了我的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
/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')
);
我正在调用actionfetchPrescriptionsFromUrl(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 passaccessToken
Sir。还有别的办法吗。或者还有其他的例子吗?
const response = yield call(getCharacters, accessToken)