You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🦉 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*asReactfrom'/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
+
5
38
👨💼 Great! Now we're ready to start using JSX in our HTML file!
0 commit comments