# Understanding React: Components, Imports, Exports, and Application Structure

Today, I started understanding how React applications work, focusing on their basic flow and structure.

Instead of jumping directly into building complex applications, I wanted to understand how everything connects behind the scenes.

Here are my key learnings.

1. Understanding the React Application Flow

I started by creating a React application using Create React App (CRA).

My first goal was to understand how a React application is structured and how its different parts work together.

I learned how to:

Create a React application.

Understand the basic application structure.

Create reusable components.

Export components from one file.

Import components into another file.

Use imported components like HTML tags.

2. Creating and Using Components

One of the first things I learned was how to create a React component.

For example:

function Welcome() { return

# Hello, React!

; }

export default Welcome;

Here, Welcome is a React component.

To use this component in another file, we first need to import it.

import Welcome from "./Welcome";

function App() { return ; }

export default App;

An interesting thing I learned is that we can use our custom components just like HTML elements.

For example:

is an HTML element.

is a React component.

Important: React component names should start with an uppercase letter.

Why?

Because React uses capitalization to distinguish between built-in HTML elements and custom React components.

Lowercase names are treated as built-in elements, while uppercase names are treated as custom components.

3. JavaScript vs JSX File Extensions

Another interesting thing I learned is that React components can be written in both .js and .jsx files.

For example:

App.js

App.jsx

Both extensions can be used for React components, provided the project tooling supports JSX transformation.

The .jsx extension simply makes it easier to identify files containing JSX.

4. Understanding index.html in Create React App

I also explored the public folder and found the index.html file.

This file acts as the HTML entry point of the application.

One interesting thing I noticed was that the HTML file doesn't contain a manually written script tag for our main React application.

So, how does React execute our JavaScript code?

The development tooling handles this process. It bundles or transforms the application and injects the required script into the generated HTML.

This happens behind the scenes, so developers don't have to manually connect every JavaScript file to the HTML document.

5. Understanding React Structure in Vite

After exploring Create React App, I also looked at how a React application is structured when created using Vite.

One important difference I noticed is the location of index.html.

In a typical Vite React project, the structure looks like this:

my-react-app/ │ ├── index.html ├── package.json ├── vite.config.js │ └── src/ ├── main.jsx ├── App.jsx └── components/ └── Welcome.jsx

Unlike Create React App, Vite keeps index.html in the project root rather than inside the public folder.

The index.html file contains a script reference to the application entry point, usually src/main.jsx.

For example:

This is where Vite starts loading the React application.

6. Understanding JSX and Multiple Elements

Another concept I learned was that JSX doesn't allow us to return multiple adjacent elements without a common parent.

For example, this won't work:

function App() { return (

# Hello

Welcome to React

); }

To solve this, we can wrap multiple elements inside a parent element.

Using a div:

function App() { return (

# Hello

Welcome to React

); }

Using a React Fragment:

function App() { return ( &lt;>

# Hello

Welcome to React

&lt;/> ); }

The interesting difference is that a div creates an additional DOM element, whereas a Fragment doesn't add an extra DOM node.

Key Takeaways

Today, I understood the following concepts:

How a basic React application is structured.

How to create reusable components.

How to export and import components.

How to use custom components like HTML elements.

Why React component names start with uppercase letters.

The difference between .js and .jsx extensions.

The role of index.html in a React application.

How Create React App and Vite organize their project structures.

Why we use div or React Fragments to wrap multiple JSX elements.

Final Thoughts

I'm trying to understand concepts by connecting the pieces rather than memorizing isolated rules.

Today wasn't about building something complex. It was about understanding the foundation of React and how its basic structure works.

One step at a time. One concept at a time.

Learning is not just about writing code; it's also about understanding why things work the way they do.
