Giter Site home page Giter Site logo

411_news_articles's Introduction

Instructions

Call the News API to populate a list of news articles using Redux Thunk


  • Look at the state.js file under the redux folder. You should see just one property called articles with an empty array present. We will populate (or replace) the array with data from the News API.

  • In the reducers.js file you should see the current reducer function for "articles". Add a case for "FETCH_ARTICLES" that simply returns "action.value"

  • In the store.js file you need to do three things:

    1. import applyMiddleware
    2. import thunk
    3. pass applyMiddleware(thunk) to the createStore function
  • Finally (for the redux folder), in actions.js, fill the "fetchArticles" function so that it calls the API endpoint (with fetch) and then dispatches the "articleAction" action creator. You will need to pass response.articles (the result of the fetch call) to that action creator to fulfil the "articles" parameter. The API endpoint to call is at the top of the file.

  • Now, in our List container we should see that there is already a mapStateToProps function that is sending in the articles array. We need to make a mapDispatchToProps function that returns a property with key, fetchArticles and value () => dispatch(fetchArticles()). Remember to import the fetchArticles action at the top of the page.

  • In the List component we simply need to create a "componentDidMount" function and call "this.props.fetchArticles", which is the redux action we just connected. You should see a list of news articles appear on the page.

411_news_articles's People

Contributors

cesarrrc avatar hipperger avatar mxviteri 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.