Before reading this article, I want to emphasize that it is meant to teach how to respond. In order to create a voting application, we need to set up the backend and the database to store the results. Here we build the front end of a simple election application using React.js.

At the end of this article, we will have an idea of the steps to follow to create a suitable application, such as B.

  1. Creating a new reaction application with NPX
  2. Add new elements
  3. Using the reactive bootstrap in our project.
  4. Adding SCSS to the Response project
  5. Parts and Drawings
  6. Working with staff and accessories

Condition

Someone with little knowledge of HTML, CSS and basic computer skills can easily understand this article.

Now let’s start building a voice application in React.

Before dealing with this request, the following picture should give us an idea of the structure of our project file.

Create a Simple Voting App Using React ←

1. Create new request

After successfully installing Node.js, you can easily create a new React project using the NPX tool with the following command.

npx selective application for interaction with creators

Now enter the project and open it with any code editor. Here I am using Visual Studio Code to edit the code.

cd vote-app
code .

Now start our reactive application with the start command in npm.

around noon

In the browser window, the React application we created opens with the address https://localhost:3000. The port may be different if 3,000 people are in use.

Create a Simple Voting App Using React ←

If you need help installing React on your system, use the links below.

Installing React on Windows, Ubuntu and MacOS

2. Install Reactive Charge Ribbon

Now install the React bootstrap package and the React bootstrap package for the base style.

nm i reactive bootstrapped

After installing these packages in our application, we get a list of bootable components to build the user interface.

3. Sass installation unit

Bootstrap allows us to create beautiful user interfaces. If more style is needed, we need to add custom CSS. However, in this tutorial we will use CSS instead of SCSS.

But we need to install the node-sass package to add SCSS support. So use the following command to install node-sass version 4.14.1. Currently, React is not compatible with the latest version of node-sass.

npm installation [email protected]

4. Create control data as JSON

Since our application has no backend or database, we need to create a JSON array.

So, in the src directory, create a lib directory and a team.json file.

{ “name”: FC Barcelona, logo
: fcb.png,
vote:0
},
{
_id : 2,
name : Juventus FC, logo
: juventus.png,
vote:0
},
{
_id : 3, name
: Manchester United F.C., Logo
: mu.png,
vote:0
}
].

5. Save Team logo images

Here we see that the order object contains _id, name, logo and votes. It contains only the name of the logo file. So we have to store images to access them.

In a shared folder, create assets and images in the folder. Now insert all logo files here.

6. Make a map of the languages that make up.

We will now create a VotingCard.jsx component in src/components to display information about each team.

It shows the team logo, the name, the number of votes and a button to add votes.

Here, the value command and the incrementCount function of the parent component (App.js) are provided as accessories.

So, when we click the vote button, it calls prop incrementCount and gives the team ID.

The function is defined in App.js and we will talk about it later.

7. App component

Remove all default code in the App.js component. Now import the react-bootstrap components, the bootstrap.css file and the teamJson array, the VotingCard component we created earlier. We also imported the styles.scss file, which we will explain later.

Now let’s look at the App() function. Here we need an initialization of the report, called commands, and a function to update the report, called setTeams.

let [team, setTeams] = useState([]) ;

Now that the Appounts component is in place, we need to assign TeamJson data for later use.

React’s useEffect feature takes care of this.

useEffect() => {
setTeams(teamsJson) ;
}, []) ;

In the return function, we show a control panel and the details of each order are sent to the voting card. This data is displayed on the front panel.

You can also see that the incrementVoteCounter function is also switched to the VotingCard component to get the teamId of the VotingCard. This teamId is used to update the voices of each team.

return (

{teams.map((team) => {
return (

incrementVoteCount(teamId)}
/>

);
})}

);

So when we click the Voting button in the VotingCard component, the _id value of the command is sent to App.js.

From there, an increase in votes should be generated. For this purpose, we have defined the function incrementVoteCount().

incrementVoteCount(teamId) function {
team = teams.map((team) => {
if (team._id === teamId) {
team.votes = team.votes + 1;
}
team return;
});
setTimes(teams);
}

This feature displays teams and expands the voting field if the team ID is moved to the displayed team feature.

We then update the status commands with the setTeams function to return the component. Otherwise, the update will not be displayed in real time.

So the full App.js component looks like this.

Our application now works exactly as shown below.

Create a Simple Voting App Using React ←

Coding folder

You can view the application live via the CodeSandbox link.

GitHub

You can always go to the GitHub repository to clone this project.

https://github.com/syamjayaraj/ReactVotingApp

Summary

In this article, we learned the basic structure of building a simple React application. This applies to theme items, accessories, reports, etc. The addition of the react-bootstrap and custom SCSS is also explained here. Combining all this, we created a voice application using React.js.

Dim:

How to load…

You may like this.

voting app tutorialreact voting componentmern voting appbuild a real-time voting appreact vote examplereact native voting apphow to create a voting system in pythonnode.js voting app

You May Also Like

🥇 Use Advanced Gmail Search  Step by Step Guide ▷ 2021

Google’s email service is considered one of the most important tools for…

Prevent Automatic Codec Download on Windows Media Player

Windows Media Player automatically loads codecs (short for decoder codecs or compressor…

How to Cast Karaoke to TV Using Chromecast

Chromecast has become enormously popular and is one of the most widely…

11 Best Hamachi Alternatives For Virtual Gaming

Hamachi is a VPN application that allows you to create a local…