Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export function loadAllWeather() {
  2.     return dispatch => {
  3.         dispatch({
  4.             type: 'LOAD_ALL_REQUEST', // это может помочь вам, если захотите сделать прелоадер
  5.         })
  6.        
  7.         fetch(`http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=ad7ce277ead15b2f7e1bdc6f7e6b7f3b`)
  8.             .then(function(response) {
  9.                 if (response.status >= 400) {
  10.                     throw new Error("Bad response from server");
  11.                 }
  12.                 return response.json();
  13.             })
  14.             .then(function(data) {
  15.                 dispatch({
  16.                     type: LOAD_ALL_WEATHER,
  17.                     payload: data, // ваши данные с сервера
  18.                 })
  19.             });
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement