diff --git a/src/App.tsx b/src/App.tsx
index 2cf5239da..8aef610c3 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,27 +1,56 @@
-import React from 'react';
+/* eslint-disable no-nested-ternary */
+import React, { useEffect, 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 [mode, setMode] = useState('all');
-
+ useEffect(() => {
+ goodsAPI.getAll().then(result => setGoods(
+ mode === 'all' ? result
+ : mode === 'five'
+ // eslint-disable-next-line max-len
+ ? result.sort((one, two) => one.name.localeCompare(two.name)).slice(0, 5)
+ : result.filter(item => item.color === 'red'),
+ ));
+ }, [mode]);
-
+ return (
+
+
Dynamic list of Goods
-
+
-
-
-);
+
+
+
+
+
+
+ );
+};
diff --git a/src/GoodsList.tsx b/src/GoodsList.tsx
index b56a4331e..304707bf9 100644
--- a/src/GoodsList.tsx
+++ b/src/GoodsList.tsx
@@ -8,7 +8,7 @@ type Props = {
export const GoodsList: React.FC = ({ goods }) => (
{goods.map(good => (
- -
+
-
{good.name}
))}
diff --git a/src/api/goods.ts b/src/api/goods.ts
index f0d1659f8..f80ab632a 100644
--- a/src/api/goods.ts
+++ b/src/api/goods.ts
@@ -7,13 +7,3 @@ export function getAll(): Promise {
return fetch(API_URL)
.then(response => response.json());
}
-
-export const get5First = () => {
- return getAll()
- .then(goods => goods); // sort and get the first 5
-};
-
-export const getRedGoods = () => {
- return getAll()
- .then(goods => goods); // get only red
-};