Giter Site home page Giter Site logo

react-promise-homework's Introduction

Homework for working with Promises (via fetch) and updating react state

if you see STRETCH GOAL - think of it as an optional additional challenge. if you see DOUBLE STRETCH GOAL - think of it as an optional additional challenge that is probably twice as hard as a regular stretch goal.

Assignment

  1. On initialization of the application, make an api request to the edamam api for cakes and display a list of cake names and the calories for the cake recipe by updating the react state via setState()

    const APP_ID = ''; // your app id here, provided to you when you sign up
    const APP_KEY = ''; // your app key here, provided to you when you sign up
    
    // this would be what I would make for the final URL
    const BASE_ENDPOINT = `https://api.edamam.com/search?app_id=${APP_ID}&app_key=${APP_KEY}`;
    // an example API request with a cake query would be
    // `${BASE_ENDPOINT}&q=cake`
    • Use the React lifecycle hook of ComponentDidMount and make your fetch request in there
    • STRETCH GOAL - Create a function based component for each recipe item, where you pass in props ie:
       <div class="recipe-list">
           {/* This should hopefully give you some direction, but ask your TAs for help if you're stuck! */}
           {this.state.recipeList.map(recipe => <Recipe someProps />)}
       </div>
  2. Handle Errors. If you get an error (lets say you turn off the internet connection)

    • All you need is to have a message of your choice display INSTEAD of a list of recipes
    • STRETCH GOAL - Make a function for displaying an error, and conditionally show the right one
    • DOUBLE STRETCH GOAL - look into creating a higher order component that can conditionally show either an error or a list!
  3. STRETCH GOAL - Make the API request happen in a reusable function that if given a string, will search the api for that string

  4. DOUBLE STRETCH GOAL - Implement a search bar (like you may have in previous assignments) - where the result of the search text generates a new list, ie - search for pies instead of cakes

  5. STRETCH GOAL - Write any kind of test for any component you make! Remember you can look at the default test file here as a reference

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.