Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Simple Todo list with add, remove, and toggle completion using useState.
import React, { useState } from 'react';
const TodoApp = () => {
const [todos, setTodos] = useState([]);
const [task, setTask] = useState('');
const addTodo = () => setTodos([...todos, { task, completed: false }]);
const toggleTodo = index => {
const newTodos = [...todos];
newTodos[index].completed = !newTodos[index].completed;
setTodos(newTodos);
};
return (
<div>
<input value={task} onChange={e => setTask(e.target.value)} />
<button onClick={addTodo}>Add</button>
<ul>{todos.map((todo, i) => <li key={i} onClick={() => toggleTodo(i)} style={{ textDecoration: todo.completed ? 'line-through' : 'none' }}>{todo.task}</li>)}</ul>
</div>
);
};
export default TodoApp;React is a declarative, component-based JavaScript library for building user interfaces, primarily for single-page applications. It allows developers to create reusable UI components and manage application state efficiently.
Origin & Creator
Developed by Jordan Walke at Facebook in 2013.
Industrial Note
React is specialized for building dynamic, responsive web and mobile UIs, particularly in SPA and complex front-end applications.