Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Use React Arrow Function Components

Define React arrow-function components, render them with JSX, pass props, use Hooks at the top level, and pass event handlers without invoking them during render.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A React arrow-function component is an arrow function that returns JSX. Define it, then render it as a JSX element: const Greeting = () => <h1>Hello</h1>; and use it as <Greeting />. React recommends functions for new components, but arrow syntax is a choice—not a requirement.

Define and render an arrow-function component

Components describe parts of a user interface. An arrow function can serve as a function component when it returns JSX:

const Greeting = () => <h1>Hello</h1>;

function App() {
  return <Greeting />;
}

Use an uppercase name for a component and place it in JSX as <Greeting />. JSX tells React that this is a component to render. Avoid calling it as Greeting() to produce UI; React should call components through JSX so it can manage rendering and component behavior. See React’s guidance on how React calls components and Hooks.

Expression body or explicit return

When the component returns one expression, you can put the JSX after the arrow without braces:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const Greeting = () => <h1>Hello</h1>;

For multiple statements, use a block body and an explicit return:

const Greeting = () => {
  const message = 'Hello';
  return <h1>{message}</h1>;
};

A function declaration is another valid way to define a function component; the arrow form is not required by React.

Pass props into the component

Props are supplied as attributes in JSX and received as the component function’s parameter. Destructuring the property you need keeps the code concise:

const Greeting = ({ name }) => <h1>Hello, {name}</h1>;

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

Here, name is an input to the component. Treat props as read-only: calculate the UI from them rather than changing them. React describes props and state as immutable snapshots, and expects rendering to be pure—calculating UI from inputs rather than performing side effects during render. See React’s purity guidance.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Hooks in the component body

An arrow-function component can use Hooks just like another function component. For example, useState provides state and a setter:

import { useState } from 'react';

const Counter = () => {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount(count + 1)}>
      {count}
    </button>
  );
};

Call Hooks at the top level of a function component or custom Hook, before any early return. Do not call them inside conditions, loops, nested functions, or event handlers. Those placements can make Hook calls happen in a different order between renders. React’s Rules of Hooks explain the restriction.

Pass event handlers instead of running them during render

An arrow function can also be an event handler. That is separate from using an arrow function to define the component. For a brief, one-off action, an inline handler is convenient:

<button onClick={() => setCount(count + 1)}>Add one</button>

For logic you may reuse or that would clutter JSX, define a named handler:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function SaveButton() {
  const handleSave = () => {
    saveDocument();
  };

  return <button onClick={handleSave}>Save</button>;
}

In both cases, the event prop receives a function. Writing onClick={handleSave()} calls the function immediately while rendering instead of waiting for a click. React’s event-handling guide shows the difference between passing and calling a handler.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Arrow components and function declarations

Both an arrow-function expression and a function declaration can define a function component. React’s component guidance focuses on using components through JSX; it does not establish that one of these two function syntaxes is faster or universally preferable. Choose a style that is clear and consistent in your codebase.

React’s Component reference says, “We recommend defining components as functions instead of classes. See how to migrate.” This is a recommendation, not a requirement: class components remain supported.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.