Component

A component is a reusable, self-contained piece of a React user interface, such as a button, form, or page. Components return JSX describing what to render and can be combined to build a whole app.

React

Components are the core building block of React. Each one is a JavaScript function (or, in older code, a class) whose name starts with a capital letter and that returns JSX. You use a component by writing it like an HTML tag: <MyButton />.

Splitting a UI into components keeps code organized and reusable — you write a piece once and use it in many places. Components can also nest inside one another to form a tree, with parent components passing data down to children through props.

Examples

JSX — The Welcome component is reused twice, so the page shows the 'Welcome back!' heading two times inside a div.

function Welcome() {
  return <h2>Welcome back!</h2>;
}

function App() {
  return (
    <div>
      <Welcome />
      <Welcome />
    </div>
  );
}

Learn it in a lesson

See also

Back to the Dictionary