Giter Site home page Giter Site logo

nikida-ks / advanced-redux-practice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from austincodingacademy/react-redux-reducer-dashboard

0.0 1.0 0.0 857 KB

Practice making a redux store, reducers and containers

HTML 35.49% CSS 0.82% JavaScript 63.69%

advanced-redux-practice's Introduction

A dashboard is a common type of user interface used to show a variety of information that is important in making decisions. It is usually read only which is perfect for practicing redux reducers. The data is currently being passed to components through props. Change the code to implement redux and remove any passing of props.

Reducers

  • Create a new folder called reducers
  • Create a file in this folder called index.js
  • Import combineReducers from redux
  • Create a reducer function for each piece of data in state.js
    • newComments
    • newTasks
    • newOrders
    • tickets
    • orders
    • tasks
    • messages
  • Remember 2 parameters state and action. Remember to return state
  • Combine the reducers and export

Create the store

  • Create a store.js file
  • Import createStore from redux
  • Import state from state.js
  • Import reducers from reducers/index
  • Create the store and export it

Provide store to components

  • In index.js
  • Import Provider from react-redux
  • Import store from store.js
  • Use Provider component to wrap App
  • Give Provider a prop “store” and the value of the store

Create Containers

  • In each Container:
  • Import connect from react-redux
  • Create a function called mapStateToProps that takes parameter state
  • Return an object. Decide what prop the component needs and this will be a key on the object
  • Decide what data from state the component needs and that will be the value on the object
  • Use the connect function and mapStateToProps to turn the component into a container
  • Export the container

ONLY make these components into Containers

  • Tickets (use as example)
  • TransactionPanel
  • TopNav
  • TasksPanel
  • Comments
  • Orders
  • Tasks

Think - Why do the other components not care about the store such that we don't need to make them Containers??

Fix

  • In App.js remove the props parameter and all instances of passing props
  • In index.js remove all instances of state and passing props to App

advanced-redux-practice's People

Contributors

jw56578 avatar kevincolten avatar

Watchers

James Cloos 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.