Before diving in, let’s understand what React is. React is a JavaScript library (a collection of code that helps build things) that makes it easier to design parts of a website. With React, you build small, reusable pieces of a website, like buttons, menus, or forms, that can be easily put together to make a full webpage.
Think of a component as a building block. Just as LEGO bricks combine to create a complex structure, components join together to form a website. A Navbar, for example, is a component that houses links to various pages on the site.
\\root
folder there’s an \\src
folder. Inside the src
folder, we want to create a folder called components
. This will hold the individual parts (or components) you create.components
folder, create a new file called Navbar.jsx
. This file will contain all of the information regarding our navbar component.Reformatting your code using Prettier: alt+shift+f
Moving a block of code up or down without copy and pasting: alt + ↑ / alt + ↓
This is especially useful when you want to create an outer HTML component that will contain your block of code.
A react component is a singular piece of UI. It contains JavaScript functions that return an HTML element.
// Navbar.jsx
import React from "react";
function Navbar() {
return <div>Ripple & Refresh</div>;
}
export default Navbar;