Create Todo list using reactJs (insert and delete element) (using Map, filter methods)

 Create Todo list using reactJs (insert and delete element) (using Map, filter methods).


 Source Code:-


App.js

import React, { useState } from "react";
import ListItem from "./ListItem";

const App = () => {
  const [listsetList] = useState('');
  const [btnsetBtn] = useState([]);

  const inputEvent = (event=> {
    setList(event.target.value);
  }

  const btnClick = () => {
    setBtn((preValue=> {
      return [...preValuelist];
    });
    setList('');
  }
  const delItems=(id)=>{
    // console.log("delete")
    setBtn((oldItem)=>{
      return oldItem.filter((arrEleindex)=>{
        return index !== id;
      })
    })
  }
  return (
    <>
      <div className="main_div">
        <div className="center_div">
          <br />
          <h1>ToDo List</h1>
          <br />
          <input type="text" onChange={inputEvent} value={list} name="" placeholder="Add a Items" />
          <button onClick={btnClick}>+</button>
          <ol>
            {btn.map((itemValueindex=> {
              return <ListItem
                  key ={index}
                  id{index}
                  text = {itemValue}
                  onSelect ={delItems}
              />
            })}
          </ol>
        </div>
      </div>
    </>
  )
}

export default App;

ListItems.js

import React from 'react'

export default function ListItem(props) {
    
    return (
        <div className="todo_style">
            <but className="btn" onClick={()=>{
                props.onSelect(props.id);
            }}></but>
            <li>{props.text}</li>
        </div>
    )
}

index.css


*{
  padding0;
  margin0;
  font-family'Merienda', cursive;
}
.main_div{
  width100%;
  height100vh;
  background#6983aa;
  displayflex;
  flex-directionrow;
  justify-contentcenter;
  align-itemscenter;
  text-aligncenter;
}

.center_div {
  width25%;
  height80vh;
  background-color#f4f4f4;
  box-shadow5px 5px 25px -5px rgba(0,0,0,0.5);
  border-radius15px;
}

h1{
  colorwhite;
  backgroundtransparent;
  background-color#8566aa;
  padding6px 0 2px 0;
  margin-bottom10px;
  box-shadow5px 5px 15px -5px rgba(0,0,0,0.3);
}

input{
  text-aligncenter;
  height30px;
  top10px;
  bordernone;
  backgroundtransparent;
  font-size20px;
  font-weight500;
  width60%;
  border-bottom2px solid #8566aa;
  outlinenone;
}

button{
  min-height40px;
  width40px;
  border-radius50%;
  border-colortransparent;
  background-color#8566aa;
  color#fff;
  font-size40px;
  bordernone;
  outlinenone;
  margin-left10px;
  box-shadow5px 5px 15px -5px rgba(0,0,0,0.3);
  cursorpointer;
}


button:hover{
  background-colorgreen;
}

ol{
  margin-top30px;
}

ol li{
  padding-left0px;
  text-alignleft;
  font-size20px;
  font-weight500;
  min-height40px;
  displayflex;
  align-itemscenter;
  color#8566aa;
  text-transformcapitalize;
}

.todo_style{
  displayflex;
  flex-directionrow;
  justify-contentleft;
  align-itemscenter;
}

.todo_style .fa-times{
  width20px;
  height20px;
  displayflex;
  justify-contentcenter;
  align-itemscenter;
  background-color#8566aa;
  border-radius50%;
  margin0 15px 0 35px;
  coloraliceblue;
  box-shadow5px 5px 15px -5px rgba(0,0,0,0.3);
}

.todo_style .fa-times:hover{
  background-colorcrimson;
}

@media (max-width768px){
  .center_div{
    width55%;
  }
}

.todo_style .fa-times {
  margin0 15px 0 15px;
  displayflex;
  justify-contentcenter;
  align-itemscenter;
}

button{
  margin-left5px;
  min-height40px;
  width40px;
  color#fff;
  font-size30px;
  
}

.but{
  margin-left5px;
  min-height40px;
  width40px;
  color#fff;
  font-size17px;
    margin-right20px;
}