How to Use React: A Beginner’s Guide to Building Interactive UIs

React is a popular JavaScript library for creating dynamic user interfaces. Its component-based architecture lets you break down complex UIs into small, reusable pieces. Below, you’ll learn the essential steps to start building your own React application.

This tutorial covers project setup, creating components, managing state, and handling user events — everything you need to build your first React app.

Article illustration

1. Set Up a New React Project

Use Vite (recommended) or Create React App to scaffold your project. Run:

  • npm create vite@latest my-app -- --template react
  • cd my-app
  • npm install
  • npm run dev

This starts a development server at http://localhost:5173.

2. Create Your First Component

Components are functions that return JSX (HTML-like syntax). Edit src/App.jsx:

function Greeting() {
  return <h1>Hello, React!</h1>;
}
export default function App() {
  return <Greeting />;
}

Each component should be a single, reusable piece of UI.

3. Manage State with useState

To make your component interactive, use the useState hook. Example:

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 returns an array: the current value and a function to update it.

4. Handle User Events

React events are written in camelCase and passed as functions. For forms, use controlled components:

function NameForm() {
  const [name, setName] = useState('');
  return (
    <input
      value={name}
      onChange={(e) => setName(e.target.value)}
      placeholder="Enter your name"
    />
  );
}

This binds the input value to state, making React the single source of truth.

Conclusion: React’s component model and hooks make building modern UIs straightforward. Start small, practice with these basics, and gradually explore advanced concepts like effects and context.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *