Portal
Search…
Setup dapp project

🌽
Create a project using create-react-app

Let's start with creating a frontend project using create-react-app.
1
npx create-react-app counter-dapp
Copied!
This command takes a little while to complete, be pertinent. You need to confirm the installation of create-react-app if it's your first time using this command.
Once the command complete, start the web app:
1
cd counter-dapp
2
yarn start
Copied!
A browser window will be opened and who the web app. You can visit http://localhost:3000/ either.

🛠
Add counter state and buttons

We'll add a simple text to show the current value of the counter state.
"Inc" and "Dec" buttons to update the counter state.
Edit src/App.js and set the App() function looks like below:
1
function App() {
2
return (
3
<div className="App">
4
<header className="App-header">
5
<h1>Counter Example</h1>
6
<p>
7
Current value: n/a
8
</p>
9
<button className="CounterButton">Inc Counter</button>
10
<button className="CounterButton">Dec Counter</button>
11
</header>
12
</div>
13
);
14
}
Copied!
Edit src/App.css and add the css class CounterButton. You can make your customizations as you like.
1
.CounterButton {
2
background-color: #4CAF50;
3
border: none;
4
color: white;
5
margin-top: 15px;
6
padding: 15px 32px;
7
text-align: center;
8
text-decoration: none;
9
display: inline-block;
10
font-size: 16px;
11
width: 200px;
12
}
Copied!
The webpage will be reloaded after you saved the files.
Now you can see we're having the basic page layout!
The source code of this chapter could be found at the revision fdb1b9e5f in the counter-dapp source repo.
Last modified 9mo ago