-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doplnění obsah lekce o stabevních vzorech
- Loading branch information
Showing
27 changed files
with
89 additions
and
639 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Prop `children` | ||
|
||
Když vytváříme znovupoužielné komponenty, často budeme chtít, aby si programátor mohl sám rozhodnout, co se v komponentě zobrazí. Mohli bychom například umožnit zobrazit uvnitř komponenty `Alert` nějaký složitější obash, než pouze textový řetězec. | ||
|
||
Například bychom chtěli mít možnost zobrazit v komponentě `Alert` několik odstavců textu: | ||
|
||
```jsx | ||
<Alert | ||
type="warning" | ||
title="Warning!" | ||
> | ||
<p>Something went a tiny bit wrong.</p> | ||
<p>But don't worry, it's not a big deal yet.</p> | ||
</Alert> | ||
``` | ||
|
||
Naše vlastní komponenty jsme zatím vždy používali jako nepárové značky, do kterých jsme posílali pouze props. Teď však najednou posíláme do komponenty `Alert` několik potomků. Abychom tyto potomky mohli zobrazit, musíme v komponentě `Alert` použít prop `children`. | ||
|
||
V Reactu je v každé komponentě k dispozici speciální prop nazvaná `children`, která obsahuje všechny do komponenty vnořené potomky, tedy jakékoli JSX prvky, které se nacházejí uvnitř značky komponenty. | ||
|
||
Obsah prop `children` pak můžeme přímo vložit do JSX komponenty na místo, kde se nám to hodí. V našem případě do elementu `.alert__body`. | ||
|
||
```jsx | ||
export const Alert = ({ type, title, children }) => { | ||
return ( | ||
<div className={`alert alert--${type}`}> | ||
<div className="alert__head"> | ||
<i className={`alert__icon fas ${selectFaIcon(type)}`}></i> | ||
<span className="alert__title">{title}</span> | ||
</div> | ||
<div className="alert__body">{children}</div> | ||
</div> | ||
); | ||
}; | ||
``` | ||
|
||
Prop `children` budeme využívat vždy, kdy budeme potřebovat napsat komponentu, která má obsahovat další prvky nebo komponenty, ale my dopředu nevíme, jaké to budou. | ||
|
||
Časté použití jsou například jsou znovupoužitelné komponenty jako různá dialogová okna, sidebary, nastylované boxy, ve kterých může být libovolný obsah, nebo obecné komponenty, které například řídí rozložení prvků na stránce. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
17 changes: 0 additions & 17 deletions
17
daweb/react/stavebni-vzory/cvlekce/platebni-plan/exercise.md
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.