For this project we were tasked to create a todo app using redux global store and react. One of the main goals is to practice working with reducers and actions to get used to selecting data from the global store and dispatching data to the global store.
The requirements for the todo app are:
- Should list all todo tasks.
- Should be able to mark a task as complete or uncomplete and switch between the two different states.
- Should be able to add and remove tasks.
- The app should show a count of either all the todos, or all uncomplete todo's or both.
- Started by writing out on paper the different components I would need.
- Created my global store, setting up the inital state to an empty array and creating the slice where the reducers will be housed.
- Then I thought about what reducers I would need and wrote the code in the global store file: One that add's a todo, one that set's the task to done and one that removes the task.
- After this I started to implement access to the store in App.js and configuring the store by using the combineReducers and configureStore and then wrapping the whole of my app and the components that will structure the app in the provider and giving it a prop of the store.
- Started selecting data from the store, using useSelector, and dispatching data to the store depending on the action the user is doing using useDispatch.
- Implemented the clear all todos button by creating a reducer that takes the current global state and replaces it with an empty array. Also implemented an empty state design which the user see's when the clear all button is clicked and there are no tasks.
- Added the time stamp for each todo by using the moment.js Library.
- I also decided to use styled components and started out by writing them in each of the components they related to. Then once I was finised with the styling I created a file for each of the styled components which I import into their specific component file.
- Implemented using local storage in the browser so whatever the initial state is it'll be retrieved from there rather than the global store. Thus enables the user to still see todo's added when the page is reloaded.
Check out my todo list here https://epic-blackwell-4f00c6.netlify.app/