From de1a92de5e91e74fcd922f703834f42816ce9285 Mon Sep 17 00:00:00 2001 From: Bohdan Dymydiuk Date: Mon, 11 Nov 2024 18:13:33 +0200 Subject: [PATCH] add task solution --- src/App.tsx | 59 ++++++++++++++++++++++++++++++++--------------- src/GoodsList.tsx | 2 +- src/api/goods.ts | 8 ++++--- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 2cf5239da..4b68e2d88 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,27 +1,48 @@ -import React from 'react'; +import { useState } from 'react'; import './App.scss'; import { GoodsList } from './GoodsList'; -// import { getAll, get5First, getRed } from './api/goods'; -// or -// import * as goodsAPI from './api/goods'; +import * as goodsAPI from './api/goods'; +import { Good } from './types/Good'; -export const App: React.FC = () => ( -
-

Dynamic list of Goods

+export const App: React.FC = () => { + const [goods, setGoods] = useState([]); - + const all = async () => { + const result = await goodsAPI.getAll(); - + setGoods(result); + }; - + const firstFive = async () => { + const result = await goodsAPI.get5First(); - -
-); + setGoods(result); + }; + + const red = async () => { + const result = await goodsAPI.getRedGoods(); + + setGoods(result); + }; + + return ( +
+

Dynamic list of Goods

+ + + + + + + + +
+ ); +}; diff --git a/src/GoodsList.tsx b/src/GoodsList.tsx index ca92d7573..f1ac29c71 100644 --- a/src/GoodsList.tsx +++ b/src/GoodsList.tsx @@ -8,7 +8,7 @@ type Props = { export const GoodsList: React.FC = ({ goods }) => (