Giter Club home page Giter Club logo

advanced-redux-fetch-practice's Introduction

Setup

  • Fork, Clone, npm install, npm start

Intro

  • The interface for this project should look familiar. It is using the same code as the express practice. We now to alter the client code to use redux thunk instead of fetch calls directly in the components.

Use local api

Create actions in actions/index.js to retrieve data

  • loadContacts
    • return a thunk function
    • make a fetch call to /contacts
    • in the second then, dispatch to contactsLoaded
  • contactsLoaded(contacts)
    • return an action
    • type is “CONTACTS_LOADED”
    • value is contacts
  • loadVehicles
    • return a thunk function
    • make a fetch call to /vehicles
    • in the second then, dispatch to vehiclesLoaded
  • vehiclesLoaded(vehicles)
    • return an action
    • type is “VEHICLES_LOADED”
    • value is vehicles
  • loadComments
    • return a thunk function
    • make a fetch call to /comments
    • in the second then, dispatch to commentsLoaded
  • commentsLoaded(comments)
    • return an action
    • type is “COMMENTS_LOADED”
    • value is comments
  • loadProducts
    • return a thunk function
    • make a fetch call to /products
    • in the second then, dispatch to productsLoaded
  • productsLoaded(products)
    • return an action
    • type is “PRODUCTS_LOADED”
    • value is products

Create actions in actions/index.js to create data

  • createProduct(product)

    • return a thunk function
    • make a fetch call to /products as a POST
    • include the product in the body
    • in the first then, dispatch to loadProducts
  • createContact(contact)

    • return a thunk function
    • make a fetch call to /contacts as a POST
    • include the contact in the body
    • in the first then, dispatch to loadContacts
  • createComment(comment)

    • return a thunk function
    • make a fetch call to /comments as a POST
    • include the comment in the body
    • in the first then, dispatch to loadComments
  • createVehicle(vehicle)

    • return a thunk function
    • make a fetch call to /vehicles as a POST
    • include the vehicle in the body
    • in the first then, dispatch to loadVehicles

Create reducers in reducers/index.js

  • Create reducers based on the state in state.js
  • Determine which action the reducers should care about
  • return the appropriate value

AppContainer

  • In AppContainer.js
  • Import connect
  • Import actions loadContacts, loadVehicles, loadComments, loadProducts
  • mapDispatchToProps for these actions to props of the same name
  • Connect and export
  • Remember how to use connect when there is no mapStateToProps

App

  • In App.js
  • call loadContacts, loadVehicles,loadComments,loadProducts in componentDidMount

Points

  • Base points - 20
  • Contacts appear in list - 10
  • Vehicles appear in list - 10
  • Comments appear in list - 10
  • Products appear in list - 10
  • Create new contact shows up in list - 10
  • Create new vehicle shows up in list - 10
  • Create new comment shows up in list - 10
  • Create new product shows up in list - 10

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.