Giter Site home page Giter Site logo

redux's Introduction

Redux & React

Topics:

  • redux package
  • react-redux package
  • Redux state vs react component state
  • <Provider> and createStore(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 state
  • actions - objects produced by action creators that will be fed through all reducers.
  • mapStateToProps(), mapDispatchToProps() & connect

Project Description

Initialize Project

  • Run create-react-app todo to create your starter application.
  • npm i --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 uses map to display it as an unordered list.

State Tree

  • 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 the todos 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.

React

  • 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 uses map 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 either true or false. You will need to send the id property along with what completed should be set to. The todos 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.

Notes/Hints

  • 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 a mapStateToProps(state) function to read from the state tree.
  • Actions require you to create a mapDispatchToProps(dispatch) function that you'll also pass to the connect function.
  • 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.

Extra Credit

  • 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.

redux's People

Contributors

sunjieming avatar seanchen1991 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.