Begin your journey with React! Learn how to set up your environment, create your first component, and understand the basics every web developer should know.
Table of content
React is a popular JavaScript library developed by Facebook for building user interfaces, particularly single-page applications. Thanks to its component-based architecture and efficient rendering, React has become an essential tool for modern web development. If you’re new to React, this guide will help you get started quickly and confidently.
node -v
and npm -v
.npx create-react-app my-app
cd my-app
npm start
npm create vite@latest my-app -- --template react
cd my-app
npm install
npm run dev
If you want to experiment fast, try online editors like CodeSandbox or StackBlitz. Choose the React template, and you’re ready to code!
React applications are built from components. Here’s a simple example:
function Welcome(props) {
return <h1>Hello, {props.name}!</h1>;
}
// Usage
<Welcome name="World" />
This creates a reusable component that greets a user by name.
React components use JSX, a syntax extension that lets you write HTML-like code directly inside JavaScript:
const element = <h1>Hello, React!</h1>;
JSX makes code more readable and expressive, but it’s transpiled to JavaScript under the hood.
useState
Components can hold their own state using the useState
hook:
import React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}
useEffect
, useContext
React is a must-learn technology for web development in 2024 and beyond. By mastering the basics—components, state, and JSX—you’ll be well on your way to building modern, responsive web apps. Happy coding!