From eb4773ef79bf20b75f8d8282eb86166c31b8b17c Mon Sep 17 00:00:00 2001 From: Heorhii Savostikov <116906180+GeorgeSavostikov@users.noreply.github.com> Date: Sat, 20 Jan 2024 22:36:48 +0200 Subject: [PATCH 1/2] Solution --- src/App.tsx | 71 ++++++++++++++++++++++++++++++++++------------- src/GoodsList.tsx | 8 ++++-- src/api/goods.ts | 11 ++++---- 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 2cf5239da..b899ce0bb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,27 +1,60 @@ -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, getRed } 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(null); - + function onselect(value: string) { + switch (value) { + case 'firstFive': { + get5First().then(setGoods); + break; + } - + case 'onlyRed': { + getRed().then(setGoods); + break; + } - + default: { + getAll().then(setGoods); + } + } + } - -
-); + return ( +
+

Dynamic list of Goods

+ + + + + + + + {goods !== null && } +
+ ); +}; diff --git a/src/GoodsList.tsx b/src/GoodsList.tsx index b56a4331e..c55c552af 100644 --- a/src/GoodsList.tsx +++ b/src/GoodsList.tsx @@ -2,13 +2,17 @@ import React from 'react'; import { Good } from './types/Good'; type Props = { - goods: Good[] + goods: Good[]; }; export const GoodsList: React.FC = ({ goods }) => (