How to get started creating a Frontend React-App
Tags: react, javascript, frontend, beginners
Published: 2022-03-14 19:46:41

1. Create a folder that you want your project to be in. 

2. cd into that folder and create a new React Project and make sure to give the project a name. 

In this example i'll use "sampleapp" as the name of the new project.


```
npx create-react-app@latest sampleapp 
```
** Once the app is done installing make sure to cd into the folder that was just created.**


Install your support libraries and styles library for some page styling so the app doesn't look plain.

```
npm i react-router-dom bootstrap 
```
 When installing Bootstrap make sure to also add the css and bundle to the index.html file.

[Getting Started with Bootstrap](https://getbootstrap.com/docs/5.1/getting-started/introduction/)


Test the server to ensure it is working 

run `npm start` then go to `localhost:3000`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7du5z8pmnwganu7dko3d.png)
 
Once you see this, your app has been successfully installed and is ready to be edited. 

**Now it's time to set up the React Router.**
Inside of index.js

add the following:
`import {BrowserRouter as Router} from 'react-router-dom`


Then you want to wrap the App component inside Router in order for the App and children will be able to use the Router.

Finally you pass the app component inside of Router so that it can have access to all the router props.

like this:

```
ReactDOM.render(
  <Router>
  <React.StrictMode>
    <App />
  </React.StrictMode>
  </Router>,
  document.getElementById('root')
);
```
Now we're ready to start customizing the application!!

in the App.js file delete everything inside the <div> so that you are left with a blank canvas.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ec2lsas0dd7o6izak4e.png)

Here we will be adding all of the routes to the different pages of the application. 

In the src Folder create a new folder called "components" and a folder called "pages"

In the **Components** folder you can add small pieces of code that are related to the User Interface. For example I added a navbar.js and a footer.js file to my components folder. 

In the **Pages** folder you can have the different pages that act as routes for the app. 

For example the **Home Page** and **About Page**. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpx22lh8mp6zms7hsbn4.png)
 

For this example I will not be styling the navigation or footer. I will simply style the components and pages so that you can get a picture of how to set up the application. 

In every page and component you will set up the basic skeleton of the page.

it will look as follows:

```
import React from "react";

const About = (props) => {
 return(
    <h1> this is the about page </h1>
)
}

export default About 
```
Once you have created the skeleton for each page, it's time to import the components, and also the components from React Router into the app.js file. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wj20npuhw0q0k8ll6zch.png)

**Now it's time to add the Routes and the Route paths.**

Inside of the returned JSX of the app.js file add the following and adjust it according to the app you want to make.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pm7jytxd3wjn271pcyp0.png)
 
In the top url search bar it look like this, when wanting to see the home page:

`http://localhost:3000/`

This is the Home page that you have created

![This is the Home page that you have created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lt8fgugb1o7zuvl8aa0.png)
 
---

**Since I want the Navbar and Footer to show on each page of the app, I will add it to the index.js file.**

To add the Navbar and Footer to the index.js file you first import the components

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w6joh6ei709xycr3wkq8.png)
 
 Then you add the the Navbar and Footer to be rendered inside the Router. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hiczbznvbhg8fpbqc6qo.png)
 
You want to make sure you add this in the order you want it to be displayed. 

Once you style your pages and components you should have a full functioning app! 

Again this is a basic setup on how to get started creating a react app. 

Have fun coding and make it a great day! :)