2017-07-14 16 views
0

私の状態でコンポーネントファイルに保存した値 "ハッシュ"を渡したいとします。私はその状態値 "ハッシュ"をURLへのパラメータとしてsagasファイルで使用します。これどうやってするの。以下はmoコードファイルです。他のファイルの状態から値を使用する方法

サガは、あなたがselectメソッドを使用することができます

import { call, put, takeLatest } from 'redux-saga/effects'; 
import { REQUEST_DATA } from './constants'; 
import { requestDataSuccess, requestDataFailed } from './actions'; 
import { fetchTxs } from './api'; 

export function fetchDataFromServer() { 
return fetch('https://blockchain.info/rawtx/${hash}') 
 .then((response) => response.json()); 
} 

function* fetchData() { 
    try { 
     const data = yield call(fetchDataFromServer); 
     yield put(requestDataSuccess(data)); 
    } catch (e) { 
     yield put(requestDataFailed(e.message)); 
    } 
} 

// Individual exports for testing 
export function* fetchSaga() { 
    // See example in containers/HomePage/sagas.js 
    yield takeLatest(REQUEST_DATA, fetchData) 
} 

// All sagas to be loaded 
export default [ 
    fetchData, 
]; 

答えて

0

を提出します。ここに公式の文書https://github.com/redux-saga/redux-saga/tree/master/docs/api#selectselector-argsがあります。それを

export const getSession = state => state.session; 

// Saga 
export function* saveChanges() { 
    while(true) { 
    yield take(SAVE_CHANGES); 
    let session = yield select(getSession); // <-- get the session 
    yield call(fetch, '/api/project', { body: session, method: 'PUT' }); 
    yield put({type: SAVE_SESSION_SUCCESS}); 
    } 
} 
を使用しての