Skip to content

Commit

Permalink
docs: add correct explanation to Fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
arimariojesus committed Nov 21, 2021
1 parent 0044601 commit cc0b2a8
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions documentation/DOC-HOME.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,48 @@ function MeuComponente() {
}
```

---

## Fragmentos

Um [Componente](https://pt-br.reactjs.org/docs/glossary.html#components) é defindo por uma função que declarada retorna um [Elemento](#elementos) React .
Os [Fragmentos](https://pt-br.reactjs.org/docs/fragments.html) permitem agrupar uma lista de filhos sem adicionar nós extras ao DOM.

```jsx
function MeuComponente() {
return <div>Olá Mundo</div>;
return (
<React.Fragment>
<div>Olá</div>
<div>Mundo</div>
</React.Fragment>
);
}
```

Isto renderizará no DOM apenas os seguintes elementos:

```html
<body>
<div>Olá</div>
<div>Mundo</div>
</body>
```

### Sintaxe Curta

Existe uma sintaxe nova e mais curta que você pode utilizar para declarar fragmentos. Parecem tags vazias:

```jsx
function MeuComponente() {
return (
<>
<div>Olá</div>
<div>Mundo</div>
</>
);
}
```

---

## Expressões

Expand Down

0 comments on commit cc0b2a8

Please sign in to comment.