Create a Component

Components are JavaScript functions or classes that accept parameters, called props, and return a description of the UI based on those parameters. In this way, you can render the HTML elements and the application data in one go, without writing additional code to update values inside the HTML. When the data changes, you pass updated props to the component. React takes care of re-rendering the page.

A component can be any JavaScript function that takes an object as a parameter and returns an element created with React.createElement. Since components are JavaScript functions, you can transform the data with the full power of JavaScript before creating the output. Our first component will be a function that takes two numbers and ...

Get React for Real now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.