-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfed414
commit 9aa6da3
Showing
3 changed files
with
60 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,53 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { get5First, getAll, getRedGoods } from './api/goods'; | ||
import './App.scss'; | ||
import { GoodsList } from './GoodsList'; | ||
import { Good } from './types/Good'; | ||
|
||
// import { getAll, get5First, getRed } from './api/goods'; | ||
// or | ||
// import * as goodsAPI from './api/goods'; | ||
export const App: React.FC = () => { | ||
const [goods, setGoods] = useState<Good[]>([]); | ||
|
||
export const App: React.FC = () => ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
const handleLoadAll = () => { | ||
getAll().then(goodsFromServer => setGoods(goodsFromServer)); | ||
}; | ||
|
||
<button type="button" data-cy="all-button"> | ||
Load all goods | ||
</button> | ||
const handleLoadFirstFive = () => { | ||
get5First().then(firstFiveGoods => setGoods(firstFiveGoods)); | ||
}; | ||
|
||
<button type="button" data-cy="first-five-button"> | ||
Load 5 first goods | ||
</button> | ||
const handleLoadOnlyRed = () => { | ||
getRedGoods().then(onlyRedGoods => setGoods(onlyRedGoods)); | ||
}; | ||
|
||
<button type="button" data-cy="red-button"> | ||
Load red goods | ||
</button> | ||
return ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
|
||
<GoodsList goods={[]} /> | ||
</div> | ||
); | ||
<button | ||
type="button" | ||
data-cy="all-button" | ||
onClick={handleLoadAll} | ||
> | ||
Load all goods | ||
</button> | ||
|
||
<button | ||
type="button" | ||
data-cy="first-five-button" | ||
onClick={handleLoadFirstFive} | ||
> | ||
Load 5 first goods | ||
</button> | ||
|
||
<button | ||
type="button" | ||
data-cy="red-button" | ||
onClick={handleLoadOnlyRed} | ||
> | ||
Load red goods | ||
</button> | ||
|
||
<GoodsList goods={goods} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters