React
functional components
web development
JavaScript
frontend development
programming
software engineering

What are React functional components?

Deepak Tewatia
August 25, 2025
3 min read

Introduction

React functional components are a simple way to build parts of a web app. They are just JavaScript functions that take in data, called props, and return what you want to see on the screen. These components are easy to use and help make your code clean and clear.

Understanding Functional Components

At their core, functional components are JavaScript functions. They can take input in the form of props, which are like parameters that hold data. Then, they return UI elements, usually in the form of JSX. JSX is a syntax extension that looks like HTML. It allows you to write HTML-like code within your JavaScript.

Why Use Functional Components?

Here’s the thing: functional components offer several advantages.

  • Simplicity: They are simpler to write and understand. You only need to focus on the task at hand, which is rendering UI based on props.
  • Performance: They can be faster than class components. Functional components do not need to manage their own state unless you use the useState hook.
  • Ease of Testing: Since they are just functions, it’s easier to test them in isolation.

Creating a Functional Component

Let’s break it down with a simple example. Here’s how to create a functional component that shows a greeting message.


function Greeting(props) {
    return <h1>Hello, {props.name}!</h1>;
}

In this example:

  • The Greeting function is the component.
  • It takes props as an argument.
  • It returns an <h1> element that shows a greeting.

Using the Component

Next, let’s see how you can use this component in your app.


function App() {
    return <Greeting name="Alice" />;
}

In the App function, we call the Greeting component and pass in a name. When the app runs, it will display a message like "Hello, Alice!" on the screen.

Props and Their Importance

Props are essential for making your components dynamic. They allow you to pass data from one component to another. Here’s something useful to remember: props are read-only. You should not change them inside your component. If you need to manage state, you can use hooks like useState or useReducer.

Hooks in Functional Components

Speaking of hooks, let’s look at how we can manage state in a functional component. The useState hook lets you add state to your functional component.


// Import useState from React
import React, { 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>
    );
}

In this example:

  • We import useState from React.
  • We create a state variable called count and a function setCount to update it.
  • When the button is clicked, we call setCount to increase the count.

Conclusion

Functional components are a great way to build your web application. They keep your code clean and organized. By using props and hooks, you can create dynamic, interactive user interfaces without the extra complexity of class components. So, whether you are just starting or looking to make your code better, using functional components is a smart choice.

For more information on React components, you can check out the official React documentation.