Advertisement
Guest User

action displayUser.js

a guest
May 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {API_KEY} from './../APIkey';
  2.  
  3. export const FETCHING_USER = 'FETCHING_USER';
  4. export const RECEIVED_USER = 'RECEIVED_USER';
  5.  
  6. const fetchingUser = () => {
  7.   return {
  8.       type: FETCHING_USER
  9.   }
  10. }
  11.  
  12. const receivedUser = (data) => {
  13.     return {
  14.         type: RECEIVED_USER,
  15.         data
  16.     }
  17. }
  18.  
  19. export const fetchingCollection = async (id) => {
  20.   return async function(dispatch) {
  21.  
  22.     dispatch(fetchingUser());
  23.  
  24.     await fetch('https://api.themoviedb.org/3/movie/'+id+'?api_key='+API_KEY+'&language=en-US')
  25.     .then( res => res.json() )
  26.     .then( data => {dispatch(receivedUser(data)); console.log(data) });
  27.   }
  28. }
  29.  
  30. export const displayCollection = async (array) => {
  31.     for(const item of array){
  32.         await fetchingCollection(item);
  33.     }
  34.     console.log('done');
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement