Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'target') while tying in input #1399

Open
rameshkondra opened this issue Sep 16, 2023 · 0 comments

Comments

@rameshkondra
Copy link

`import React, { useState } from "react";
import "../Styles/Todos.css";

function Todos() {
const [task, setTask] = useState("");
const [todos, setTodos] = useState([]);

let onInputEnter = (e) => {
setTask(e.target.value);
};

let onSubmitHandler = (e) => {
e.preventDefault();
let newTodos = [...todos, task];
setTodos(newTodos);
setTask("");
};

let deleteHandler = (indexValue) => {
let newTodos = todos.filter((todo, index) => index !== indexValue);
setTodos(newTodos);
};

return (



Todos Application using React js

    <form onSubmit={() => onSubmitHandler()}>
      <input
        className="input-field"
        name="task"
        placeholder="Enter here..."
        value={task}
        onChange={() => onInputEnter()}
      />
      &nbsp;
      <button className="btn" name="Add" type="submit">
        Add
      </button>
    </form>
    {todos.map((todos, index) => {
      return (
        <div key={index}>
          <h3>
            {todos} &nbsp; &nbsp;
            <button onClick={() => deleteHandler(index)}>delete</button>{" "}
          </h3>
        </div>
      );
    })}
  </center>
</div>

);
}

export default Todos;
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant