Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Syntax | Functional Components and Hooks
React Tutorial
course content

Conteúdo do Curso

React Tutorial

React Tutorial

1. Getting Started
2. Lifecycle Methods
3. Functional Components and Hooks
4. Advanced Topics

bookSyntax

In React, functional components are defined as JavaScript functions that take in props as an argument and return JSX. Here is the basic syntax for a functional component:

The function name (in this case, MyComponent) is used to represent the component, and the function takes in a single argument called props. props stand for "properties" and is an object that contains all the data that is passed to the component from its parent.

Inside the function, you can return JSX by wrapping it in parentheses. For example, here is a functional component that renders a simple heading:

You can then use this component in your JSX by calling it like a regular HTML tag:

This will render the following JSX:

Functional components can also accept additional arguments, such as event handlers or values that are calculated within the component. For example, here is a functional component that renders a button that increases a counter when clicked:

This component accepts an onClick prop that is a function that is called when the button is clicked, and a count prop that is the current value of the counter. You can then use this component like this:

This will render a button with the current count value and will call the handleClick function when the button is clicked.

Functional components are a simple and powerful way to define components in React, and they are a great choice for many use cases. They are easy to understand and use, and they can make your code more concise and readable.

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1
some-alt