💻 Getting started


👶 Exercise 1: A simple counter

After running npm start, you should see a bare webpage with only a counter (at 0) and an increment button. This is the Counter component being rendered to the screen.

The Counter component is exported from src/components/Counter.js and imported to src/App.js, where it’s rendered by the App component. (The App component itself is rendered in src/index.js.)

Task

You only need to edit src/components/Counter.js in this exercise. Implement the Counter component by completing the following:

  1. Declare a new state variable for the counter with useState
  2. Edit the JSX in the component’s return statement so that it renders the current value of the counter, not just 0
  3. Edit the handleOnClick event handler so that it increments the counter by 1 whenever it’s called (i.e. whenever the increment button is clicked)

Before any clicks

Before any clicks

After clicking Increment once

After clicking Increment once

After clicking Increment twice

After clicking Increment twice


🌏 Exercise 2: Capital Finder

Next, let’s take a look at the CapitalFinder component in src/components/CapitalFinder.js. This component displays a message that tells you what the capital city of a given country is, with the country set to Australia by default.

The CapitalFinder component is already included in src/App.js, except it and its import statement have been commented out. You can uncomment them now and see the change in your web browser. As you can see, the features don’t entirely work yet.