GithubHelp home page GithubHelp logo

gizemcdeniz / react-hooks-use-effect-lab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-curriculum/react-hooks-use-effect-lab

0.0 0.0 0.0 220 KB

HTML 23.41% JavaScript 65.53% CSS 11.06%

react-hooks-use-effect-lab's Introduction

React useEffect Lab

Learning Goals

  • Use the useEffect hook with the dependencies array
  • Use a cleanup function with useEffect to stop background processes

Overview

In the labs for this section, we're going to be building a trivia app! The first feature we're going to work on is the Question component.

There is some starter code for us to work with. There's a Question component already set up to display the question and a list of possible answers. It's also hooked up to its parent component, App, so that it has access to all the props it needs.

The feature we're going to build out using useEffect is a countdown timer, so that the user has to answer each question within 10 seconds.

Deliverables

When the Question component renders, create a side effect using useEffect and use setTimeout to run a callback function after 1 second.

Inside the callback function for setTimeout, use the setTimeRemaining function to decrease the amount of time remaining by 1 every 1 second.

When timeRemaining hits 0, do the following:

  • reset timeRemaining back to 10 seconds, so our next question will have a fresh timer; and
  • call the onAnswered callback prop with a value of false (onAnswered(false)), to trigger some behavior in the App component.

You should also use the cleanup function for useEffect to clean up after the timeout function.

Make sure to pay attention to any warning/error messages in the console as a result of using useEffect, and clean them up by providing any necessary dependencies in the second argument of useEffect.

If you're stuck on getting the timer working, or encountering some strange behavior, make sure to check out the resources below!

Resources

react-hooks-use-effect-lab's People

Contributors

ihollander avatar lizbur10 avatar gizemcdeniz 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.