liveBook · Manning

Rendering

As explained in React Quickly, Second Edition

A render method is a component method that returns the element tree representing the component's user-interface output.

In a class-based React component, render() returns the element tree that represents the component’s user-interface output. It is the only required method when defining a component with class Name extends React.Component. section 2.4 section 2.8

A render method follows a few practical rules:

  • Return one root element created with React.createElement(), either an HTML tag or another custom component. section 2.4
  • Wrap multiple same-level elements in an HTML container or React.Fragment. section 2.4
  • Reuse the component by creating multiple instances, rather than repeating the same raw elements. section 2.4 section 2.8

Rendering three reusable links

class Link extends React.Component {\n render() {\n return React.createElement(\n "p",\n null,\n React.createElement("a", { href: "//react.dev" }, "Read more about React")\n );\n }\n}\n\nconst group = React.createElement(\n React.Fragment, null,\n React.createElement(Link),\n React.createElement(Link),\n React.createElement(Link)\n);\n\nReactDOM.createRoot(document.getElementById("root")).render(group); section 2.4

How React Quickly, Second Edition covers it

How deep it goes
Explains the required method, returned element shape, single-root constraint, and fragment workaround without discussing rendering internals.
Examples
Demonstrates a reusable Link component that renders three identical links inside a React fragment.
What you can do after
Build reusable class components with render(), React.createElement(), fragments, and multiple component instances.
How it connects
Connects rendering with custom components, React elements, React fragments, JSX, and props.

Also explained in

Compare how 4 books explain rendering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.