1. Home
  2. /
  3. React
  4. /
  5. Todo List with useState

Todo List with useState - React Typing CST Test

Loading…

Todo List with useState — React Code

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 Language Guide

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.

Primary Use Cases

  • ▸Single-page web applications (SPAs)
  • ▸Dynamic user interfaces for web apps
  • ▸Mobile apps via React Native
  • ▸Reusable component libraries
  • ▸Interactive dashboards and admin panels

Notable Features

  • ▸Component-based architecture
  • ▸Virtual DOM for optimized rendering
  • ▸JSX syntax for combining HTML and JS
  • ▸One-way data binding (props)
  • ▸Hooks for state and lifecycle management

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.

More React Typing Exercises

React Counter with useStateReact Theme Toggle with ContextReact Fetch Data with useEffectReact Form HandlingReact Modal ComponentReact useReducer CounterReact Context Counter ExampleReact Tab ComponentReact LocalStorage Counter

Practice Other Languages

CPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlin