This is a simple Todo Web App built for learning purposes, which demonstrates how to manage state in a React application using Redux Toolkit. The app allows users to add, edit, and delete todos, while leveraging Redux Toolkit for effective state management.
- Add Todo: Allows users to add new tasks to the list.
- Edit Todo: Enables users to update the title of an existing task.
- Delete Todo: Allows users to remove tasks from the list.
- Redux Toolkit Integration: The app uses Redux Toolkit to manage the state, ensuring predictable and scalable state management across the app.
This project aims to help you learn:
- State Management with Redux Toolkit: You will learn how to use Redux Toolkit to manage global state in a React app.
- Action Creators and Reducers: Learn how to define and dispatch actions to modify the state in Redux.
- React-Redux Integration: Understand how to connect Redux store with React components using
useDispatchanduseSelector. - Conditional Rendering in React: Learn how to conditionally render components based on Redux state, such as showing the edit form when a todo is selected for editing.
- React: Frontend JavaScript library for building the user interface.
- Redux Toolkit: A state management library that simplifies the process of working with Redux.
- JavaScript: The programming language used for building the application.
- CSS: Basic styling for the UI components.
The project is organized in the following way:
- redux:
- Contains the Redux slice (
todoSlice.js) to manage todos and the app’s state. - Stores actions like
addTodo,removeTodo,updateTodo, andsetEditTodoId.
- Contains the Redux slice (
- components:
- AddTodo: A form that allows users to add or edit a todo.
- TodoList: Displays the list of todos with options to edit or delete each todo.
- App.js:
- The root component that uses
Providerto wrap the app and pass down the Redux store.
- The root component that uses
- redux/store.js:
- Configures the Redux store and combines reducers.
- Adding Todos: Users can enter a todo title and click the "Add Todo" button. The app dispatches an
addTodoaction to the Redux store, adding the new todo to the state. - Editing Todos: When users click the "Edit" button next to a todo, the app sets the
editTodoIdin the Redux store to the todo’s ID. The AddTodo component then populates the form with the current title of that todo, allowing users to edit it. - Removing Todos: Clicking the "Delete" button next to a todo dispatches the
removeTodoaction, which removes the todo from the state.
To run this project locally, follow these steps:
git@github.com:devhimal/todo-redux-toolkit.git
cd todo-redux-toolkitnpm installnpm startThe app will be available at http://localhost:3000.
/src
/components
AddTodo.js // Component to add or edit todos
TodoList.js // Component to list todos
/store
store.js
/redux
todoSlice.js // Redux slice for todos
App.js // Main application component
index.js // App entry point
- Redux Toolkit: Learn how Redux Toolkit simplifies the process of writing Redux logic with slices, reducers, and actions.
useDispatchanduseSelector: Understand how to dispatch actions and select state from the Redux store in React components.- State Updates: Learn how state is updated in response to user actions and how these updates are reflected in the UI using Redux state.
This project is designed to help you understand Redux Toolkit and its integration with React for managing application state. It is a beginner-friendly project that gives you hands-on experience with modern state management techniques using Redux Toolkit.