GithubHelp home page GithubHelp logo

roboman-sil / fetch-react-lab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thoughtworks-jumpstart/fetch-react-lab

0.0 0.0 0.0 90 KB

A kata to practice usage of fetch() API in React components

HTML 20.53% CSS 5.68% JavaScript 73.78%

fetch-react-lab's Introduction

Fetch + React lab

Prerequisite knowledge

Getting started

  • Fork and clone repo
  • cd fetch-react-lab
  • Get an NewsAPI API key here (Click on the 'Get API key' button on the top right)
  • In your browser, make a GET request for the following URL: https://newsapi.org/v2/everything?sources=hacker-news&apiKey=REPLACE_WITH_YOUR_API_KEY (you should see a JSON response with news articles)
  • Create a new file in the project directory and name it .env.local. Place the following snippet in the file:
REACT_APP_NEWSAPI_API_KEY=REPLACE_WITH_YOUR_API_KEY
  • Note: Because this .env.local file contains secrets, it is listed in .gitignore and will not be committed in git

  • Run npm start

Tasks

  • In NewsFeed.js#componentDidMount(), start by making a GET request to the defined URL using fetch(). Here's a short snippet to get your started. You can also use async/await syntax if you like.
fetch(URL)
  .then(response => {
    return response.json();
  })
  .then(responseBody => console.log(responseBody))
  • In NewsFeed.js#componentDidMount(), call setState to store the articles returned from the fetch request in the state object of the NewsFeed component.

  • Incrementally flesh out the data in this.state.articles. Try to create new components (e.g. an Article component) as you see fit.

  • Bonus: implement the following features in your app

    • allow users to upvote / downvote articles

fetch-react-lab's People

Contributors

davidtan-tw avatar davified avatar songguoqiang 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.