a Todo List App, using Redux to store state
Topics:
redux
packagereact-redux
package- Redux state vs react component state
<Provider>
andcreateStore(reducer)
- One state object for entire application
reducer
functions control the values for the state properties.container
components are React components that connect to the Redux stateactions
- objects produced byaction creators
that will be fed through all reducers.mapStateToProps()
&connect
- Run
create-react-app todo
to create your starter application. - Now that you have created your
todo
directory, cd into it. yarn add redux react-redux
ornpm install --save redux react-redux
This command will install the needed dependencies.- You will create a todo list using React and Redux.
- Use the movies project as a reference.
- The general flow of steps will be to create your store, create your reducers, create your containers, and then create the action creators.
- When you add a new item to the todo array an action containing the new todo object will be dispatched through all of the reducers.
- To display the todo list you will create a container that receives the
todos
array as a prop and then usesmap
to display it as an unordered list.
- Your application should have an input field, a submit button, and a list of items that represents your todo list.
- Your application's state tree should have a single property called
todos
. It should take the same form as the object shown below.
{
todos: []
}
- Each
todo
item that is in thetodos
array should have the following format:
{
value: 'Walk the dog.',
completed: false
}
- You will create your store in
src/index.js
. The<Provider >
component will wrap<App />
and you will pass the created store into<Provider >
as one of its properties. Use this repository as a reference.
- When you type a new todo list item into the input field and press the submit button you should call an action creator that adds a new todo item to the
todos
array on the application state tree. - When the user presses submit you will invoke the appropriate action creator which will then have its new action fed through all of the reducers.
- You will display the todo list by creating a container that receives the application's
todos
array as a prop. That container then usesmap
to display the array. - When you click on each todo list item you will dispatch an action that will toggle that todo item's
completed
property to eithertrue
orfalse
. You will need to send theid
property along with whatcompleted
should be set to. Thetodos
reducer will return a brand new array that will replace the old array. We do not mutate the original array but rather replace it with a brand new version.
- You should only need one reducer. This reducer will control the
todos
array property on the state tree. - You will have several action creators. One for adding a new todo item and another for toggling each todo item.
- Containers require
connect
and amapStateToProps(state)
function to read from the state tree. - Actions creators should be passed inside an object as the second argument to the
connect
function inside components that need access to the Redux store. - http://redux.js.org/ has a todo list as an example project in their documentation. Feel free to use this as a reference as well.
- Implement the ability to delete todo list items. You can create a button next to each todo list item and when it is pressed it will call an action creator that will dispatch an action that removes the specified todo list item from the
todos
array. - Use
localStorage
to make the data persist.