- Import the
Counter
component from filecomponents/Counter.js
toApp.js
and render it inside the main<div>
- Add the
useState
hook in theCounter
component to keep track of the internal count. - On click of the button the value of the internal counter should increment by 1.
- Add another button to the
Counter
component. - On click of this new button, the current count will double (multiply current value by 2)
FYI: You can comment out the Counter
component in App.js once you finish it so it doesn't distract you in the following tasks.
- Import the
Lottery
component from filecomponents/Lottery.js
toApp.js
and render it inside the main<div>
- Add the
useState
hook in theLottery
component to keep track of the lottery numbers. - On click of the button the next number should be added to the array.
State can be used for conditional rendering where we want to display different things based on the state. We might have multiple state variables in one component.
- Import the
WinningNumbers
component from filecomponents/WinningNumbers.js
intocomponents/Lottery.js
- Change the
Lottery
component in the following way:- if the count of numbers in the state is lower than 10, it displays the UI to roll next number (
<div>
withclassName="TodaysNumbers"
) - if the count of numbers in the state is 10, it will display the
WinningNumbers
component, passing the current numbers as props
- if the count of numbers in the state is lower than 10, it displays the UI to roll next number (
- Inspect the
WinningNumbers
andNumbers
components incomponents/WinningNumbers.js
- The
Numbers
component should change colors based on the selected option inWinningNumbers
- Find out why it is not working and fix it.
- Import the
WindowSizer
component from filecomponents/WindowSizer.js
toApp.js
and render it inside the main<div>
- Add the
useEffect
hook in theWindowSizer
component to update the window dimension every time it resizes. Use thewindow.addEventListener('resize', () => { /* your set state functions here */ });
function to update the dimensions (See https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event) - Make sure you clean up the listener in the cleanup function with
window.removeEventListener
- Import the
Stopwatch
component from filecomponents/Stopwatch.js
toApp.js
and render it inside the main<div>
- Modify the
useEffect
hook in theStopwatch
component to not increment the time unless therunning
state variable istrue
. - Make sure you specify all the dependencies correctly for the
useEffect
- Make sure the
Reset
button in theStopwatch
component works. It should stop the timer and reset time to 0.
- Import the
StarWars
component from filecomponents/StarWars.js
toApp.js
and render it inside the main<div>
- Add the
useEffect
hook in theStarWars
component to call the Star Wars API and fetch data about a selected movie - Make sure you specify all the dependencies correctly for the
useEffect
- Make sure you avoid race conditions and ignore stale results (See https://beta.reactjs.org/apis/react/useEffect#fetching-data-with-effects)
- Update the
select
inStarWars
component to use dynamic data fetched from the Star Wars API. You can use thefetchMovieList
helper to get the data.