From a223674ae384fca0223a3012ca6f947008e83fe6 Mon Sep 17 00:00:00 2001 From: Oleksandr Boiko Date: Mon, 29 Jan 2024 19:52:59 +0200 Subject: [PATCH] add solution --- src/App.tsx | 66 +++++++++++++++++++++++++++++++++++------------ src/GoodsList.tsx | 6 ++++- src/api/goods.ts | 6 +++-- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 2cf5239da..bfdd9a53c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,27 +1,59 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.scss'; import { GoodsList } from './GoodsList'; +import { Good } from './types/Good'; -// import { getAll, get5First, getRed } from './api/goods'; +import { getAll, get5First, getRedGoods } from './api/goods'; // or // import * as goodsAPI from './api/goods'; -export const App: React.FC = () => ( -
-

Dynamic list of Goods

+export const App: React.FC = () => { + const [goods, setGoods] = useState([]); - + const handleOnClickAll = () => { + getAll() + .then((good) => setGoods(good)); + }; - + const handleOnClickFive = () => { + get5First() + .then((good) => setGoods(good)); + }; - + const handleOnClickRed = () => { + getRedGoods() + .then((good) => setGoods(good)); + }; - -
-); + return ( +
+

Dynamic list of Goods

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