From 148b07682ef5349bc36580f0f38048818cb4e7a7 Mon Sep 17 00:00:00 2001 From: Nazar Dudnyk Date: Thu, 11 Jan 2024 16:47:16 +0200 Subject: [PATCH] add task solution --- src/App.tsx | 65 +++++++++++++++++++++++++++++++++-------------- src/GoodsList.tsx | 6 ++++- src/api/goods.ts | 6 +++-- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 2cf5239da..4eef4d6a4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,27 +1,54 @@ -import React from 'react'; +import React, { 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 { getAll, get5First, getRedGoods } 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 showAllGoods = () => { + return getAll().then(good => setGoods(good)); + }; - + const showFirstFiveGoods = () => { + return get5First().then(good => setGoods(good)); + }; - + const showRedGoods = () => { + return getRedGoods().then(good => setGoods(good)); + }; - -
-); + return ( +
+

Dynamic list of Goods

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