연습 1

6009 단어
import React, { useEffect, useState } from "react";

const HelloWorld = () => {
  const [result, setResult] = useState([]);
//   useEffect(() => {
//     filterDeveloper();
//   }, []);
  const data = [
    {
      name: "Rajasekar",
      title: "Developer",
    },
    {
      name: "Ganesh",
      title: "Manager",
    },
    {
      name: "Arun",
      title: "Developer",
    },
  ];

  const filterDeveloper = () => {
    let test = data.filter((item) => {
      return item.title === "Manager";
    });
    setResult(test);
  };
  const style1 = {
    color:"white"
  }
  const style= {
    backgroundColor: "red",
    ...style1
  }



  return (
    <>
    {result.map((item, index) => (
        <div key={item.name} className="test" style={style}>
          {index + 1} {item.name} - {item.title}
        </div>
      ))}
      <button onClick={filterDeveloper}>Test</button>
    </>
  );
};

export default HelloWorld;

좋은 웹페이지 즐겨찾기