Skip to content

Commit 073f5c3

Browse files
committed
Simplify RandomAppList
1 parent 290b2f6 commit 073f5c3

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"pretty-quick": "^2.0.1"
4949
},
5050
"scripts": {
51-
"build": "gatsby build && yarn build:lambda",
51+
"build": "yarn build:app && yarn build:lambda",
5252
"build:app": "gatsby build",
5353
"build:lambda": "netlify-lambda build src/lambda",
5454
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",

src/components/RandomAppList.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,20 @@ const appList = [
4141
]
4242

4343
const RandomAppList = () => {
44-
const [dappsList, setDapps] = useState({ dapps: [] })
44+
const [randomAppList, setRandomAppList] = useState([])
4545

46-
const sortList = () => {
46+
useEffect(() => {
4747
const list = appList.map((item) => {
4848
item.randomNumber = Math.floor(Math.random() * appList.length)
4949
return item
5050
})
51-
5251
list.sort((a, b) => a.randomNumber - b.randomNumber)
53-
setDapps({ dapps: list })
54-
}
55-
56-
useEffect(() => {
57-
sortList()
52+
setRandomAppList(list)
5853
}, [])
5954

6055
return (
6156
<ul>
62-
{dappsList.dapps.map((item, idx) => {
57+
{randomAppList.map((item, idx) => {
6358
return (
6459
<li key={idx}>
6560
<Link to={item.url}>{item.name}</Link>

0 commit comments

Comments
 (0)