redux-thunk , fetch () .
:
1) , , :
export function fetchData() {
const options = {
method: 'GET',
headers: {
'Authorization': 'Client-ID xx'
}
}
return (dispatch) => {
return fetch('yourUrl.json', options)
.then(response => response.json())
.then(data => dispatch(receiveYourData(data)))
.catch(err => console.log(err));
}
}
receiveYourDatastrong > - , , :
export function receiveYourData (payload = []) {
return {
type: RECEIVE_DATA,
payload: payload
}
}
, , .
( ), fetchDatastrong > componentDidMount ( :)).
, , Example.
:)