Code Monkey home page Code Monkey logo

react-redux-blog's Introduction

react-redux-blog

Render a list of blog posts using Redux-Thunk and Axios to make a request to JSON Placeholder API.

App Overview + Lessons Learned

  1. Used Redux Thunk and wired it up to Redux store through the use of applyMiddleware.

  2. Action Creators w/ Redux Thunk

  • Whenever we make an API request from an Action Creator, always make use of some middleware (ex. Redux-Thunk) to handle asynchronrous action creators.
  • Rules have changed. Action Creators no longer need to return an Action object -- can also optionally return a function.
  • If we return a function, it will be automatically be called with the dispatch and getState arguments (essentially giving us total control over both changing and getting data out of Redux store.
  1. Solved problem of overfetching data:
  • Solution V1: Used Lodash memoize function
  • Solution V2: Created an Action Creator (fetchPostsAndUsers) that calls other Action Creators (fetchPosts and fetchUsers), and dispatch those Action Creators. Used several Lodash and JS functions to find a unique user id (instead of fetching complete list of users in API): chain, map, uniq, forEach.
  1. Reducers w/ Redux Thunk
  • Whenever we run Reducers, it will run with previous state as the first argument (default state set to empty array).
  • Use switch/case syntax to handle every action (opposed to an if-statement)
  • Return a new array/object of state with [...state] - must not mutate its input state.

react-redux-blog's People

Contributors

carolinechong avatar

Watchers

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