You are viewing a single comment's thread. Return to all comments →
function App({ articles }) { const [rows, setRows] = useState(articles.toSorted((a, b) => b.upvotes - a.upvotes)); const handleMostUpvoted = () => { setRows(rows.toSorted((a, b) => b.upvotes - a.upvotes)) }; const handleMostRecent = () => { setRows(rows.toSorted((a, b) => Date.parse(b.date) - Date.parse(a.date))) }; // snip }
// snip <tbody> {articles.map(i => ( <tr data-testid="article" key={i.title}> <td data-testid="article-title">{i.title}</td> <td data-testid="article-upvotes">{i.upvotes}</td> <td data-testid="article-date">{ i.date }</td> </tr> ))} </tbody> // snip }
Seems like cookies are disabled on this browser, please enable them to open this website
Article Sorting
You are viewing a single comment's thread. Return to all comments →
Easy Answer
App
Artciles