Posts

Showing posts from January, 2025

Add-Edit_delete

 import React, { useState } from "react"; function App() {   const [tasks, setTasks] = useState([]);   const [newTask, setNewTask] = useState("");   const [isEditing, setIsEditing] = useState(false);   const [currentTaskIndex, setCurrentTaskIndex] = useState(null);   const addTask = () => {     if (newTask.trim()) {       setTasks([...tasks, newTask]);       setNewTask("");     }   };   const editTask = (index) => {     setNewTask(tasks[index]); // Set the current task to the input field     setIsEditing(true);     setCurrentTaskIndex(index);   };   const saveTask = () => {     if (newTask.trim()) {       const updatedTasks = [...tasks];       updatedTasks[currentTaskIndex] = newTask;       setTasks(updatedTasks);       setNewTask("");       setIsEditing(false); ...

counter_New counter

 import React, { useState } from 'react'; const Counter = () => {   const [counters, setCounters] = useState([0]);   // Function to add a new counter   const addCounter = () => {     setCounters([...counters, 0]);   };   // Function to handle increment   const increment = (index) => {     const newCounters = [...counters];     newCounters[index] += 1;     setCounters(newCounters);   };   // Function to handle decrement   const decrement = (index) => {     const newCounters = [...counters];     if (newCounters[index] > 0) {       newCounters[index] -= 1;     }     setCounters(newCounters);   };   return (     <div>       {counters.map((count, index) => (         <div key={index} style={{ marginBottom: '10px' }}>           <h3>Count...