-
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.
Merge pull request #655 from Czechitas-podklady-WEB/654-react-2-aktua…
…lizace-lekce React 2: Aktualizace lekce
- Loading branch information
Showing
16 changed files
with
132 additions
and
62 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
## Cvičení: Efekty a volání API | ||
|
||
::exc[cvlekce/efekty] | ||
::exc[cvlekce/prazsky-cas] | ||
::exc[cvlekce/vyber-zony] |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
## Cvičení: Formulářové prvky | ||
|
||
::exc[cvlekce/binding] | ||
::exc[cvlekce/registrace] | ||
::exc[cvlekce/vyber-zeme] | ||
|
||
## Bonusy | ||
|
||
Pokud máte ještě čas, můžete si vyzkoušet následující cvičení, případně si je nechte jako úložky na doma. | ||
|
||
::exc[cvlekce/zasilani-newsletteru] |
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,9 @@ | ||
--- | ||
title: Data binding | ||
lead: Vyzkoušejte si obousměrný data binding. | ||
demand: 3 | ||
solutionAccess: lock | ||
--- | ||
|
||
1. Vytvořte si repozitář ze šablony [cviceni-data-binding](https://github.com/Czechitas-podklady-WEB/cviceni-data-binding). | ||
1. Následujte instrukce z README repozitáře. |
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,9 @@ | ||
--- | ||
title: Efekty | ||
lead: Vyzkoušejte si vytvořit jednoduché efekty. | ||
demand: 3 | ||
solutionAccess: lock | ||
--- | ||
|
||
1. Vytvořte si repozitář ze šablony [cviceni-react-efekty](https://github.com/Czechitas-podklady-WEB/cviceni-react-efekty). | ||
1. Následujte instrukce z README repozitáře. |
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
26 changes: 4 additions & 22 deletions
26
daweb/react/formulare-efekty/cvlekce/registrace/exercise.md
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
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
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
2 changes: 2 additions & 0 deletions
2
daweb/react/formulare-efekty/cvlekce/zasilani-newsletteru/exercise.md
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
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
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,54 @@ | ||
## Efekty se závislostmi | ||
|
||
Zatím jsme viděli efekty, které se spouštějí pouze jednou, tedy ve chvíli, kdy se komponenta poprvé objeví na stránce. Občas však potřebujeme efekt, který se spustí pokaždé, když se změní nějaká stavová proměnná nebo _prop_. Takový efekt vyrobíme tak, že do hranatých závorek napíšeme stavovou proměnnou nebo _prop_, na kterou má efekt reagovat, nebo-li na které spuštění efektu záviset. | ||
|
||
```js | ||
const Komponenta = () => { | ||
const [datum, setDatum] = useState('2022-05-14'); | ||
|
||
useEffect(() => { | ||
console.log(`Hodnota stavové proměnné datum je ${datum}.`); | ||
}, [datum]); | ||
|
||
// … | ||
}; | ||
``` | ||
|
||
Tato technika se nám hodí nejčastějí ve chvíli, kdy chceme stáhnout nějaká data z API ve chvíli, kdy komponenta změní svůj stav. V našem příkladu si stáhneme jméno z API, které má svátek v den, který uživatel vybere v kalendáři. | ||
|
||
```jsx | ||
export const HomePage = () => { | ||
const [name, setName] = useState(''); | ||
const [datum, setDatum] = useState('2022-11-11'); | ||
|
||
useEffect(() => { | ||
const fetchName = async () => { | ||
const [rok, mesic, den] = datum.split("-"); | ||
const response = await fetch( | ||
`https://nameday.abalin.net/api/V1/getdate?day=${den}&month=${mesic}` | ||
); | ||
const data = await response.json(); | ||
setName(data.namedays.cz); | ||
}; | ||
|
||
fetchName(); | ||
}, [datum]); | ||
|
||
return ( | ||
<> | ||
<div className="container"> | ||
<h1>Svátky</h1> | ||
<label> | ||
Vyberte datum:{" "} | ||
<input | ||
type="date" | ||
value={datum} | ||
onChange={(event) => setDatum(event.target.value)}; | ||
/> | ||
</label> | ||
<div className="nameday">V tento den má svátek {name}</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
``` |
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
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
title: Formulářové prvky, efekty | ||
lead: 'Zapojíme do našich React aplikací formulářové prvky a ukážeme si, jak pomocí efektů volat API.' | ||
access: 'claim' | ||
lead: Zapojíme do našich React aplikací formulářové prvky a ukážeme si, jak pomocí efektů volat API. | ||
access: claim | ||
sections: | ||
- formularove-prvky | ||
- cv-formularove-prvky | ||
- efekty | ||
- efekty-api | ||
- specializovane-efekty | ||
- efekty-zavislosti | ||
- cv-efekty-api | ||
- shrnuti |
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
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,7 @@ | ||
## Shrnutí | ||
|
||
Po této lekci byste měli vědět a znát | ||
|
||
- co to je obousměrný data binding a jak propojit stav s obsahem políčka ve formuláři, | ||
- jak v Reactu vytvořit jednoduchý efekt a načíst pomocí něj data z API, | ||
- jak používat pokročilejší efekty se závislostmi. |
This file was deleted.
Oops, something went wrong.