thisのAPI呼び出しでは、react-reduxとredux-sagaを使用します。私の目標は、別のURLで別のAPI呼び出しを行い、別のページでそれらを使用することです。それを達成する方法?複数のサプレッサー
サガ:
import { take, put,call } from 'redux-saga/effects';
import { takeEvery, delay ,takeLatest} from 'redux-saga';
function fetchData() {
return fetch("https://api.github.com/repos/vmg/redcarpet/issues?state=closed")
.then(res => res.json())
.then(data => ({ data }))
.catch(ex => {
console.log('parsing failed', ex);
return ({ ex });
});
}
function* yourSaga(action) {
const { data, ex } = yield call(fetchData);
if (data)
yield put({ type: 'REQUEST_DONE', data });
else
yield put({ type: 'REQUEST_FAILED', ex });
}
export default function* watchAsync() {
yield* takeLatest('BLAH', yourSaga);
}
export default function* rootSaga() {
yield [
watchAsync()
]
}
アプリケーション:
import React, { Component } from 'react';
import { connect } from 'react-redux';
class App extends Component {
componentWillMount() {
this.props.dispatch({type: 'BLAH'});
}
render(){
return (<div>
{this.props.exception && <span>exception: {this.props.exception}</span>}
Data: {this.props.data.map(e=><div key={e.id}>{e.url}</div>)}
</div>);
}
}
export default connect(state =>({
data:state.data , exception:state.exception
}))(App);
私の目標は、私は別のコンポーネントで使用する別の武勇伝を作ることです、そして両者とのない混乱に。それは可能ですか?
を[ここ](https://github.com/yelouafi/redux-saga/issues/178#issuecomment-249249953)、 2つの異なるAPI呼び出しを使用するようにサンプルを変更しました。あなたはそれを機能させるためにそれを拡張することができるはずです:http://www.webpackbin.com/VkdjuU02Z –