Beginner's Roadmap: Building Your First App with React

Beginner's Roadmap: Building Your First App with React

📝Introduction

React is one of the most popular JavaScript libraries [not framework] for building user interfaces. Whether you're new to programming or transitioning from another framework, React offers a flexible and intuitive approach to web development. In this guide, I’ll walk you through the basics of React, setting up your environment, and building your very first app.

⁉️What is React?

React is a popular JavaScript library developed by Facebook (now Meta) for building interactive user interfaces. It uses a component-based approach where UI elements are broken down into reusable pieces, and it efficiently updates and renders these components when data changes.

🤔Why Learn React?

  • Component-based architecture.

  • Huge community and ecosystem.

  • Used by big companies (Facebook, Instagram, Netflix).

  • Easier to manage large applications


  1. Getting Started: Setting Up Your Environment

  1. Set up React

npx create-react-app my-first-app
cd my-first-app
npm start
  1. Explain folder structure

    React’s folder structure might look intimidating at first, but here’s a breakdown of its key files:

my-react-app/
├── public/
│   ├── index.html       # Root HTML file
│   ├── favicon.ico      # App favicon
│   └── assets/          # Public static assets (images, fonts)
├── src/
│   ├── components/      # Reusable React components
│   │   ├── Header.js    # Example header component
│   │   └── Footer.js    # Example footer component
│   ├── pages/           # Page components (if applicable)
│   │   ├── Home.js      # Home page component
│   │   └── About.js     # About page component
│   ├── App.js           # Root app component
│   ├── index.js         # Entry point for React app
│   ├── styles/          # CSS or SCSS files
│   │   └── App.css      # Example global styles
│   └── utils/           # Helper functions (optional)
│       └── api.js       # Example API functions
├── .gitignore           # Files to ignore in version control
├── package.json         # Project configuration and dependencies
├── README.md            # Project documentation
└── yarn.lock /          # Dependency lock file (or package-lock.json)
    package-lock.json

Personal opinion

Even though the mentioned process is very easy to install reactjs using npx create-react-app my-app will make your folder bulky, and take lots of time so, instead of using this one, we will use a bundler called vite.

What is Vite?

Vite is a modern front-end build tool that offers a faster and leaner development experience. It provides:

  • The lightning-fast cold server starts using native ES modules

  • Hot Module Replacement (HMR) that stays fast regardless of app size

  • True on-demand compilation

  • Out-of-the-box support for TypeScript, JSX, CSS

The main advantage of Vite over Create React App is its superior performance and smaller bundle size*, making it an excellent choice for modern React development.*

npm create vite@latest

However, by doing this you won’t find the node module so you need to install the node module as well.

npm install

Now let’s build your first component

  1. What is a Component?

A component is a small, reusable piece of UI. It’s the building block of any React app.

  1. Code Example: Creating a Simple Component

     function Greeting() {
         return <h1>Hello, React!</h1>;
     }
    
     export default Greeting;
    
  2. How to Use This Component in App.js

import Greeting from './Greeting';

function App() {
    return (
        <div>
            <Greeting />
        </div>
    );
}

export default App;

💡Conclusion

You’ve now set up your first React app, built a simple component, and learned the basics of React’s component-based architecture. This is just the beginning of your journey. React has a vast ecosystem, and every project you build will deepen your understanding.