React-sagaでリクエストからjsonを取得したい!私のサガが生成するデータをどのように取得するのか疑問に思っていました.takeLatestで「REQUEST_DONE」アクションを監視し、再レンダリングするcomponentWillMountでジェネレーター関数を呼び出すという考えがあります。
しかし、コンポーネントの 1 つで react-saga を使用するのは悪い考えだと思います。ガイダンスをお願いします
私の佐賀ファイル:
export function* Saga() {
yield fetch(url, {
method: 'GET',
headers: {
'Accept': '...',
'Content-Type': 'application/json'
}
})
.then(response => {
return response.json();
})
.then(json => {
return json;
})
.catch(ex => {
console.log('parsing failed', ex)
})
}
export default function* watchAsync() {
console.log(yield Saga().next().value); // gets the value correctly
yield* takeLatest('BLAH', Saga);
}
私のコンポーネント
...
componentWillMount() {
const { store } = this.context;
store.dispatch({type: 'BLAH'});
// I want the request data
}
render() { ... }