• + 0 comments

    All tests passed:

    import "h8k-components";

    import Articles from "./components/Articles";

    import "./App.css"; import { useState } from "react";

    function App({ articles }) { const [sortedArticles, setSortedArticles] = useState( [...articles].sort((a, b) => b.upvotes - a.upvotes) );

    const handleMostUpvoted = () => { // Logic for most upvoted articles const updated = [...sortedArticles].sort((a, b) => b.upvotes - a.upvotes); setSortedArticles(updated); };

    const handleMostRecent = () => { // Logic for most recent articles const updated = [...sortedArticles].sort( (a, b) => new Date(b.date) - new Date(a.date) ); setSortedArticles(updated); }; return ( <> Sort By Most Upvoted Most Recent ); }

    export default App;

    import React from "react";

    function Articles({ articles }) { return ( Title Upvotes Date

          {articles.map((article,index) =><tr data-testid="article" key={article.id}>
            <td  data-testid="article-title">{article.title}</td>
            <td data-testid="article-upvotes">{article.upvotes}</td>
            <td data-testid="article-date">{article.date}</td>
          </tr> )}
    
        </tbody>
      </table>
    </div>
    

    ); }

    export default Articles;