npx create-react-app [app-name]
[app-name]
in the current directorycd [app-name]
src
folder that we won’t need
src
folder from our provided starter filesnpm start
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
.)
You only need to edit src/components/Counter.js
in this exercise. Implement the Counter
component by completing the following:
useState
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
After clicking Increment once
After clicking Increment twice
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.