Skip to content

Commit 290b2f6

Browse files
authored
Merge pull request #1163 from developerfred/issue/1040
chore: fixed list shuffles on RandomAppList
2 parents 8193865 + 1d8e059 commit 290b2f6

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/components/RandomAppList.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react"
1+
import React, { useEffect, useState } from "react"
22
import Link from "./Link"
33
import Translation from "./Translation"
44

@@ -41,14 +41,25 @@ const appList = [
4141
]
4242

4343
const RandomAppList = () => {
44-
const list = appList.map((item) => {
45-
item.randomNumber = Math.random()
46-
return item
47-
})
48-
list.sort((a, b) => a.randomNumber - b.randomNumber)
44+
const [dappsList, setDapps] = useState({ dapps: [] })
45+
46+
const sortList = () => {
47+
const list = appList.map((item) => {
48+
item.randomNumber = Math.floor(Math.random() * appList.length)
49+
return item
50+
})
51+
52+
list.sort((a, b) => a.randomNumber - b.randomNumber)
53+
setDapps({ dapps: list })
54+
}
55+
56+
useEffect(() => {
57+
sortList()
58+
}, [])
59+
4960
return (
5061
<ul>
51-
{list.map((item, idx) => {
62+
{dappsList.dapps.map((item, idx) => {
5263
return (
5364
<li key={idx}>
5465
<Link to={item.url}>{item.name}</Link>

0 commit comments

Comments
 (0)