React Tutorials For Beginners

A plain-English guide to learning React from zero, covering components, props, state and effects, with small examples you can type out yourself.

React Tutorials For Beginners A plain English guide to learning React from zero, with small examples you can type out yourself. If you have learned some HTML, CSS and JavaScript and want to build real web apps, React is one of the best next steps. It powers sites and apps used by millions of people, and the skills carry over to jobs, freelance work and your own projects. This guide walks you through what React is, how to set it up, and the core ideas you need to start building. What is React? React is a JavaScript library for building user interfaces. Instead of writing one huge page, you build small, reusable pieces called components, such as a button, a navigation bar or a product card, and then combine them into a full page. Three reasons beginners like React: • Reusable pieces. Write a component once and use it anywhere. • It updates the page for you. You describe what the screen should look like, and React keeps it in sync when your data changes. • Huge community. There are endless tutorials, packages and answers to your questions. What you should know first You don't need to be an expert, but you should be comfortable with: • HTML and CSS basics • JavaScript variables, functions, arrays and objects • Arrow functions, template strings and array methods like map() If const double = (n) = n 2; looks familiar, you're ready. Setting up your first project Install Node.js (the LTS version), then open a terminal and run: npm create vite@latest my first app template react cd my first app npm install npm run dev Open the address the terminal prints (usually http://localhost:5173). You should see a starter page. Any change you save in your editor appears in the browser straight away. Vite is the tool that runs your project. It is fast and is what most new React projects use today. Your first component Open src/App.jsx, delete what's inside, and write: function App() { return <h1 Hello, React!</h1 ; } export default App; A component is just a JavaScript function that returns what should appear on screen. Two rules to remember: 1. Component names start with a capital letter (App, not app). 2. A component returns one parent element. Wrap several elements in a <div or an empty fragment < ...</ . JSX: HTML inside JavaScript The HTML looking code above is called JSX. It lets you write markup inside JavaScript. A few differences from normal HTML: • Use className instead of class. • Close every tag, e.g. <img / and <br / . • Put JavaScript inside curly braces {}. function Welcome() { const name = "Ibrahim"; return <h2 className="title" Welcome, {name}!</h2 ; } Anything inside {} is evaluated as JavaScript, so you can show variables, do maths or call functions. Props: passing data to components Props let you customise a component, like arguments to a function. function ProfileCard({ name, role }) { return ( \ <div className="card" \ <h3 {name}</h3 \ <p {role}</p \ </div ); } function App() { return ( \ < \ <ProfileCard name="Ada" role="Engineer" / \ <ProfileCard name="Tunde" role="Designer" / \ </ ); } One component, two different cards. Props flow down from parent to child, and a component should never change its own props. State: data that changes Props come from outside. State is data a component owns that can change over time. You create it with the useState hook. import { useState } from "react"; function Counter() { const \[count, setCount] = useState(0); return ( \ <div \ <p You clicked {count} times</p \ <button onClick={() = setCount(count + 1)} Click me</button \ </div ); } useState(0) gives you two things: the current value (count) and a function to change it (setCount). When you call setCount, React re renders the component with the new value. Never change state directly with count = count + 1, because React won't know anything changed. Handling events React events use camelCase names like onClick, onChange and onSubmit, and you pass them a function. function NameInput() { const \[name, setName] = useState(""); return ( \ < \ <input value={name} onChange={(e) = setName(e.target.value)} / \ <p Hello, {name "stranger"}!</p \ </ ); } The input's value is stored in state, and the screen updates with every keystroke. This pattern is called a controlled input and you will use it constantly. Rendering lists To show many items, use map() and give each item a unique key. const skills = \["HTML", "CSS", "JavaScript", "React"]; function SkillList() { return ( \ <ul \ {skills.map((skill) = ( \ <li key={skill} {skill}</li \ ))} \ </ul ); } The key helps React track which item is which. Use a stable value such as an id, not the array index when items can be reordered. Conditional rendering Show different things depending on state: function Status({ isOnline }) { return <p {isOnline ? "Online" : "Offline"}</p ; } For "show this or nothing", use &&: {isLoggedIn && <Dashboard / }. Fetching data with useEffect The useEffect hook runs code after the component appears on screen, which makes it the usual place to load data. import { useEffect, useState } from "react"; function Posts() { const \[posts, setPosts] = useState(\[]); useEffect(() = { \ fetch("https://jsonplaceholder.typicode.com/posts? limit=5") \ .then((res) = res.json()) \ .then(setPosts); }, \[]); return ( \ <ul \ {posts.map((p) = ( \ <li key={p.id} {p.title}</li \ ))} \ </ul ); } The empty array \[] at the end means "run this once, when the component first appears." Forgetting it is a classic beginner bug that causes endless requests. A suggested project structure As your app grows, keep things tidy: src/ components/ reusable pieces (Button, Navbar, Card) sections/ bigger page blocks (Hero, Contact) hooks/ your own custom hooks data/ static content App.jsx main.jsx One component per file, named after the component, keeps everything easy to find. Common beginner mistakes • Lowercase component names. <card / is treated as an HTML tag. Use <Card / . • Changing state directly. Always use the setter function. • Missing key in lists. React warns you in the console. Add one. • Forgetting the dependency array in useEffect. • Putting everything in one component. Split big components into smaller ones early. Practice projects The fastest way to learn is to build. Try these in order: 1. Counter app. Increase, decrease, reset. 2. To do list. Add, tick off and delete tasks. 3. Weather or quotes app. Fetch data from a free API. 4. Personal portfolio. Show your projects, skills and contact details. 5. Mini shop. Product list, cart and a total price. Each project introduces one or two new ideas, so you grow without being overwhelmed. Where to go next Once you're comfortable with components, props, state and effects, explore: • React Router for multi page apps • Tailwind CSS for fast styling • Context API for sharing data without passing props through every level • A backend such as Supabase or Firebase for databases and logins • Deploying your finished app on Cloudflare Pages, Netlify or Vercel The official documentation at react.dev has an excellent interactive tutorial and is worth working through alongside this guide. Final thoughts React feels like a lot at first, but it really comes down to a few ideas: build small components, pass data in with props, keep changing data in state, and let React update the screen. Type out the examples above, break them, fix them, and then build something of your own. Consistency beats speed. Even 30 minutes a day will get you comfortable within a few weeks. Happy coding!