0
私は初めてredux thunk
を使用しています。連鎖操作の適切な方法は何ですか?reduxサンクの連鎖操作の適切な方法は?
ユーザー入力が与えられた後で、データがGoogle Maps API
の応答がある場合は、すぐにそのデータを使用してその場所の天気を取得したいと考えています。 Redux thunk
は動作していますが、最初の操作(ロケーションの取得)のみです。 Data2
(request2
)はいつもundefined
ですが、それはなぜですか?
export function fetchLocation(city) {
const urlGoogle = `https://maps.googleapis.com/maps/api/geocode/json?address=${city}&key=${API_KEY_GOOGLE}`;
const request = axios.get(urlGoogle);
return (dispatch) => {
request.then(({ data }) => {
dispatch({ type: FETCH_LOCATION, payload: data });
const lat = data.results["0"].geometry.location.lat;
const lng = data.results["0"].geometry.location.lng;
const urlWunder = `https://api.wunderground.com/api/${API_KEY_WUNDERGROUND}/forecast10day/q/${lat},${lng}.json`;
console.log(urlWunder); // Link is ok, it works in browser
const request2 = axios.get(urlWunder);
request2.then(({ data2 }) => {
console.log('Data2', data2); // Getting undefined, why ?
dispatch({ type: FETCH_WEATHER, payload: data2 });
});
});
};
}
ありがとうございます@markerikson! –