Advertisement
Guest User

async react

a guest
Jun 2nd, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function fetchDishesAsync(
  2.   setDishesContent,
  3.   onDishClickHandler,
  4.   setLoaded
  5. ) {
  6.   return await axios(URL).then((res) => {
  7.     products = res.data;
  8.     setDishesContent(
  9.       <FlatList
  10.         keyExtractor={(item) => item.id.toString()}
  11.         data={res.data}
  12.         renderItem={({ item }) => (
  13.           <Dish
  14.             title={item.title}
  15.             image={item.photo}
  16.             content={item.short_description}
  17.             price={item.price}
  18.             onclickMore={onDishClickHandler}
  19.           />
  20.         )}
  21.       />
  22.     );
  23.     setLoaded(true);
  24.   });
  25. }
  26.  
  27.  
  28.  
  29. //ВЫЗОВ
  30. console.log("LOADING...")
  31. useEffect(() => {
  32.     fetchDishesAsync(setDishesContent, onDishClickHandler, setLoaded);
  33.   }, []);
  34. console.log("LOADED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement