Skip to content

Commit 5224f1d

Browse files
committed
sync
1 parent 257632c commit 5224f1d

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

exercises/03.using-jsx/01.solution.compiler/README.mdx

+33
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,37 @@
22

33
<EpicVideo url="https://www.epicreact.dev/tutorials/get-started-with-react/compiling-jsx/solution" />
44

5+
🦉 Let's break down the key changes in our `script` tag:
6+
7+
1. `type="text/babel"` and `data-type="module"`:
8+
9+
- `type="text/babel"` tells Babel to transpile this script, allowing us to use JSX and modern JavaScript features.
10+
- `data-type="module"` indicates that this script should be treated as a module after Babel transpilation. This enables us to use `import` statements.
11+
12+
We use both instead of just `type="module"` because browsers don't natively understand JSX. Babel needs to transform our code first, then it can be treated as a module.
13+
14+
2. Importing React:
15+
We've changed from:
16+
17+
```javascript
18+
import { createElement } from '/react.js'
19+
```
20+
21+
to:
22+
23+
```javascript
24+
import * as React from '/react.js'
25+
```
26+
27+
This imports all exports from React as a namespace called `React`. It's beneficial because:
28+
29+
- It provides access to all React APIs, not just `createElement`.
30+
- When using JSX, the transpiler will convert JSX elements to `React.createElement` calls, so we need the `React` namespace in scope.
31+
32+
🔍 To dive deeper into these concepts, check out these resources:
33+
34+
- [📜 Babel documentation on browser usage](https://babeljs.io/docs/babel-standalone)
35+
- [📜 React documentation on JSX](https://react.dev/learn/writing-markup-with-jsx)
36+
- [📜 MDN on JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
37+
538
👨‍💼 Great! Now we're ready to start using JSX in our HTML file!

exercises/03.using-jsx/05.problem.fragments/README.mdx

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22

33
<EpicVideo url="https://www.epicreact.dev/tutorials/get-started-with-react/fragments" />
44

5-
🦉 One feature of JSX that you'll find useful is called
6-
["React Fragments"](https://react.dev/reference/react/Fragment). It's a special
7-
kind of component from React which allows you to position two elements
8-
side-by-side rather than just nested.
5+
🦉 One feature of JSX that you'll find useful is called ["React Fragments"](https://react.dev/reference/react/Fragment).
96

10-
Let's say we wanted to do the same thing as above, except we didn't want the
11-
`container` `div`. So, we wanted to just create:
7+
React Fragments allow you to group multiple elements without adding an extra
8+
DOM node. This lets you return multiple elements side-by-side from a component
9+
without needing a wrapper div. It's useful for avoiding unnecessary markup
10+
that could affect styling or layout.
11+
12+
We have currently the following code:
13+
14+
```html
15+
<div className="container">
16+
<p>Here's Sam's favorite food:</p>
17+
<ul className="sams-food">
18+
<li>Green eggs</li>
19+
<li>Ham</li>
20+
</ul>
21+
</div>
22+
```
23+
24+
We want to do the same thing as above, except we don't want the `container` `div`. So, we want to just create:
1225

1326
```html
1427
<p>Here's Sam's favorite food:</p>

0 commit comments

Comments
 (0)