Code Monkey home page Code Monkey logo

todoapp's Introduction

Basic React ToDo app

Creating a basic ToDo app using React and React state hook to be able to create a list of things that we need to get done!

This is primarily for learning and to have a better understanding of React, React useState, and useEffect.

Add notes here:

Code from before:

import { useState } from 'react'
function App() {
  // Similar to C#/Java getters and setters
  const [newItem, setNewItems] = useState("");
  const [items, setItems] = useState([])

  const handleInputChange = (event) => {
    setNewItems(event.target.value);
  }

  const addTodo = (event) => {
    event.preventDefault();

    if (!newItem) {
      alert("Please enter an item!")
      return;
    }
    const newObj = {
      id: items.length + 1,
      value: newItem
    }
    setItems(oldList => [...oldList, newObj]);
    setNewItems("");
  }

  const deleteItems = (id) => {
    const newArr = items.filter(item => item.id !== id);
    setItems(newArr);
  }

  return (
    <div className='container'>
      <h1 className='header-title'>TODO</h1>
      <form onSubmit={addTodo} className='form-el'>
        <input
          className='input-el'
          value={newItem}
          onChange={handleInputChange}
        /><button className='button-el'>Add</button>

        <ul>

          {items.map(item =>
            <li key={item.id}>
              {item.value}<button className='delete-btn' onClick={() => deleteItems(item.id)}>X</button>
            </li>)
          }
        </ul>
      </form>
    </div>

  )
}

export default App

todoapp's People

Contributors

jcast24 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.