2016-08-29 10 views
3

Привет Как я читать данные, возвращающиеся из выборки по телефону:Redux-Saga не смог правильно прочитать ответ от выборки апи

export function* fetchMessages(channel) {  
    yield put(requestMessages()) 
    const channel_name = channel.payload 
    try {  
     const response = yield call(fetch,'/api/messages/'+channel_name) 

     const res = response.json() 
      console.log(res) 
     yield put(receiveMessages(res,channel)) 


    } catch (error){  
     yield put(rejectMessages(error)) 
    }  
}  

Когда я console.log (Рез) я получаю:

Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined} 
__proto__ 
: 
Promise 
[[PromiseStatus]] 
: 
"resolved" 
[[PromiseValue]] 
: 
Array[7] 

Как мне получить «информацию» (сторона Array [7] от этого обещания? Я новичок на все это. Спасибо

ответ

2

response.json() является асинхронным и возвращается обещает

изменения этого

const res = response.json() 

к

const res = yield response.json() 

webpackbin Пример