Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
Create a Simple Form Application using React Redux
Next article icon

Create a To-Do List App using React Redux

Last Updated : 23 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A To-Do list allows users to manage their tasks by adding, removing, and toggling the completion status for each added item. It emphasizes a clean architecture, with Redux state management and React interface rendering.

Todo-List-App
Todo App

Prerequisites

  • Node.js
  • React
  • React-Redux

Approach

  • Create a new React project using Create React App and install Redux and React Redux to manage application state.
  • Create a store for State management. Here, we use createStore to create store and combine all reducers. Define reducer ( adding, removing, and toggling to-do ) here.
  • Create a functional component (App.js) that represents the main application and connect the component to the Redux store using connect from React Redux.
  • Create a CSS file(App.css) for styling the input field, buttons and to-do list.

Steps to Create Application

Step 1: Create React Application named todo-list-app and navigate to it using this command.

npx create-react-app todo-list-app
cd todo-list-app

Step 2: Install required packages and dependencies.

npm install  react-redux redux

Step 3: Check package.json file for updated and installed dependencies, it will look like the below file.

 "dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^9.1.1",
"redux": "^5.0.1",
},

Step 4: Run the application, start your application by navigating to todo-list-app and use the below command.

npm start

Project Structure:

file-structure
File Structure

Example: The below code will explain the use of react-redux to create todo list in react.

CSS
/* App.css */  #app {     display: flex;     flex-direction: column;     text-align: center; }  input {     padding: 10px 20px;     border: 1px solid black;     border-radius: 10px; }  button {     padding: 10px 20px;     border: 1px solid transparent;     border-radius: 10px;     background-color: rgba(204, 204, 204, 0.713);     cursor: pointer; }  button:hover {     background-color: rgba(7, 162, 7, 0.568); }  ul li {     list-style: none; }  .todo button {     margin: 5px; } 
JavaScript
// App.js   import "./App.css"; import React, { useState } from "react"; import { connect } from "react-redux";  const App =  ({ todos, addTodo, removeTodo, toggleTodo }) => {     const [text, setText] = useState("");      const handleAddTodo = () => {         if (text.trim() !== "") {             addTodo({                 id: new Date().getTime(),                 text,                 completed: false,             });             setText("");         }     };      const handleRemoveTodo = (id) => {         removeTodo(id);     };      const handleToggleTodo = (id) => {         toggleTodo(id);     };      return (         <div id="app">             <div>                 <h1>To-Do List</h1>                 <input                     type="text"                     value={text}                     onChange={(e) =>                          setText(e.target.value)}                     placeholder="Enter a task..."                 />                 <button onClick={handleAddTodo}>                     Add                 </button>                 <ul>                     {todos.map((todo) => (                         <li                             className="todo"                             key={todo.id}                             style={{                                 textDecoration: todo.completed ?                                  "line-through" : "none",                                 color: todo.completed ?                                  "red" : "black",                             }}                             onClick={() => handleToggleTodo(todo.id)}                         >                             {todo.text}                             <button onClick=                                 {() => handleRemoveTodo(todo.id)}>                                 Remove                             </button>                         </li>                     ))}                 </ul>             </div>         </div>     ); };  const mapStateToProps = (state) => ({     todos: state.todos, });  const mapDispatchToProps = (dispatch) => ({     addTodo: (todo) =>          dispatch({              type: "ADD_TODO",              payload: todo          }),     removeTodo: (id) =>          dispatch({              type: "REMOVE_TODO",              payload: id          }),     toggleTodo: (id) =>          dispatch({              type: "TOGGLE_TODO",              payload: id          }), });  export default connect     (mapStateToProps, mapDispatchToProps)(App); 
JavaScript
// index.js  import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App"; import store from "./store"; import { Provider } from "react-redux";  const root = ReactDOM.createRoot   (document.getElementById("root")); root.render(   <Provider store={store}>     <App />   </Provider> ); 
JavaScript
// store.js  import { createStore } from "redux"; const initialState = {     todos: [], };  const rootReducer =     (state = initialState, action) => {         switch (action.type) {             case "ADD_TODO":                 return {                     ...state,                     todos: [                         ...state.todos,                         action.payload                     ],                 };             case "REMOVE_TODO":                 return {                     ...state,                     todos: state.todos.filter(                         (todo) => todo.id !==                             action.payload),                 };             case "TOGGLE_TODO":                 return {                     ...state,                     todos: state.todos.map((todo) =>                         todo.id === action.payload                             ? {                                 ...todo,                                 completed:                                     !todo.completed                             }                             : todo                     ),                 };             default:                 return state;         }     };  const store = createStore(rootReducer); export default store; 

Output:

Todo-List-App
Todo App

Next Article
Create a Simple Form Application using React Redux

S

sandeepxt99
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • React-Redux

Similar Reads

  • How to create a food recipe app using ReactJS ?
    We are going to make a food recipe app using React.js. Pre-requisite:React hooksReact componentsJavaScript ES6API CSSApproach: Here in this app we should have a component where we are going to show our food recipes. And we need to fetch all the required food recipes using a food recipe API. We will
    4 min read
  • Create a News Reader app using React-Native
    Creating the News Reader application using React-Native language is an exciting project. Using this project, the users can read the news in the application itself, by filtering them according to the categories as per their interest. In this article, we will develop the complete News Reader applicati
    5 min read
  • How to Create ToDo App using React Native ?
    In this article, we'll see how to create a ToDo app using React Native. An ideal illustration of a basic application that can be developed with React Native is a ToDo app. This app enables users to generate, modify, and remove tasks, assisting them in maintaining organization and concentration. Reac
    4 min read
  • Create a Simple Form Application using React Redux
    In this article, we make a simple project of form application built using React and Redux. The main purpose of the application is to collect user information through a form consisting of fields for name, email, message and submit button. It's built with React for the user interface and Redux for man
    3 min read
  • Create a Food Reciepe App using React-Native
    In this React-Native article, we will be developing an interactive Food Recipe Application. In this application, the users can be able to search for any food recipe in the search box. Then, according to the search query, the results will be fetched through an API and will be displayed in the applica
    5 min read
  • How to Create a Basic Notes App using ReactJS ?
    Creating a basic notes app using React JS is a better way to learn how to manage state, handle user input, and render components dynamically. In this article, we are going to learn how to create a basic notes app using React JS. A notes app is a digital application that allows users to create, manag
    4 min read
  • Create a To Do List using Bootstrap 5
    A To-Do List is a tool for organizing tasks, allowing users to list, prioritize, and manage their activities, ensuring efficiency and productivity in completing them. Here we will create a ToDo list using Bootstrap. We will create our layout or component using Bootstrap predefined utilities and comp
    3 min read
  • Create ToDo App using ReactJS
    In this article, we will create a to-do app to understand the basics of ReactJS. We will be working with class based components in this application and use the React-Bootstrap module to style the components. This to-do list can add new tasks we can also delete the tasks by clicking on them. The logi
    3 min read
  • Creating a Travel Journal App using React
    The Travel Journal App project is a web application developed using React. This travel journal app will allow users to record their travel experiences and manage their entries efficiently. By leveraging the power of React for the frontend and Bootstrap for styling, we'll create an interactive and vi
    5 min read
  • Create a Dashboard App using React-Native
    A dashboard app using react native is a software application designed to provide a consolidated and visual representation of important information, data, or features in a single, easily accessible interface. Dashboards are commonly used in various industries to help users monitor, analyze, and manag
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences