-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
VasylynaBC
committed
Nov 6, 2024
1 parent
e7e80f9
commit 687641d
Showing
3 changed files
with
42 additions
and
20 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,47 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import './App.scss'; | ||
import { GoodsList } from './GoodsList'; | ||
|
||
// import { getAll, get5First, getRed } from './api/goods'; | ||
import { getAll, get5First, getRedGoods } from './api/goods'; | ||
import { Good } from './types/Good'; | ||
// or | ||
// import * as goodsAPI from './api/goods'; | ||
|
||
export const App: React.FC = () => ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
export const App: React.FC = () => { | ||
const [users, setUsers] = useState<Good[]>([]); | ||
|
||
<button type="button" data-cy="all-button"> | ||
Load all goods | ||
</button> | ||
function allGoods () { | ||
return getAll().then((userslist) => { | ||
setUsers(userslist); | ||
}); | ||
} | ||
function getFisrt () { | ||
return get5First().then((userslist) => { | ||
setUsers(userslist); | ||
}); | ||
} | ||
function getRed () { | ||
return getRedGoods().then((userslist) => { | ||
setUsers(userslist); | ||
}); | ||
} | ||
return ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
|
||
<button type="button" data-cy="first-five-button"> | ||
Load 5 first goods | ||
</button> | ||
<button type="button" onClick={allGoods} data-cy="all-button"> | ||
Load all goods | ||
</button> | ||
|
||
<button type="button" data-cy="red-button"> | ||
Load red goods | ||
</button> | ||
<button type="button" onClick={getFisrt} data-cy="first-five-button"> | ||
Load 5 first goods | ||
</button> | ||
|
||
<GoodsList goods={[]} /> | ||
</div> | ||
); | ||
<button type="button" onClick={getRed} data-cy="red-button"> | ||
Load red goods | ||
</button> | ||
|
||
<GoodsList goods={users} /> | ||
</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