Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState, useEffect } from "react";
  2. import { sortBy } from "../../utils/sortBy";
  3.  
  4. export default function Table(props) {
  5.   const { data, setData } = props;
  6.  
  7.   function clickSort(key) {
  8.     setData([...rowData].sort(sortBy(key)));
  9.   }
  10.  
  11.   const table = rowData.map((row, index) => {
  12.     return <div key={index}>{row.name}</div>;
  13.   });
  14.  
  15.   return (
  16.     <div>
  17.       <button onClick={() => clickSort("name")}>Click to sort by Name</button>
  18.       <button onClick={() => clickSort("id")}>Click to sort by ID</button>
  19.       {table}
  20.     </div>
  21.   );
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement