• + 0 comments

    import "h8k-components"; import { useState, useEffect } from "react"

    import Articles from "./components/Articles";

    import "./App.css";

    function App({ articles }) {

    const [sortArtiles, setSortArticles] = useState([]) const handleMostUpvoted = () => { // Logic for most upvoted articles let nexsortArtiles = [...articles]?.sort((a, b) => (b.upvotes) - (a.upvotes)) setSortArticles(nexsortArtiles) };

    const handleMostRecent = () => { // Logic for most recent articles let nexsortArtiles = [...articles]?.sort((a, b) => new Date(b.date) - new Date(a.date)) setSortArticles(nexsortArtiles) };

    useEffect(() => { if (articles.length) { setSortArticles([...articles].sort((a, b) => b.upvotes - a.upvotes)); } }, [articles]) return ( <> Sort By Most Upvoted Most Recent ); }

    export default App;