From the course: React Practice for Beginners: Build and Modify Basic Components

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Defining functional components

Defining functional components

- [Instructor] Let's talk about defining functional components. In React, almost everything you build is a component. A component is a reusable function that returns to user interface. The simplest type of component is a functional component, just a regular JavaScript function that returns JSX. There are also class components. Those are created by creating a class. We won't see them here. Instead, let's check out an example of simple functional component that displays a single user's name. I've created a new project, 2-using-components-props. The UserName you can see is a functional component. This is because it's a regular function that returns JSX. In App, which is also a functional component, this UserName component is used like a custom HMTL tag, as you can see on line 10. This is the basic structure for every React component, a function that returns JSX. It's important that what it's returning is only one root element. And that means that this is valid, but this is not. Because…

Contents