Skip to content

Commit ffa8b33

Browse files
committed
Switch React.Fragment out for span
This will make the DOM easier to reason about and a clearer 1:1 mapping. Then I also don't gloss over the `</>` part. Hat tip to C. Lates.
1 parent e928b1c commit ffa8b33

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

pages/react/getting-started.mdx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ This comes with live reloading, so you can go into a file, change it, and see
173173
the changes.
174174

175175
<Callout>
176-
🐢 Software Engineering is about making changes and validating them as quickly
177-
as possible. If you're spending your time <em>waiting</em> for something, ask
178-
yourself, "is there a faster way?"
176+
🐢 Software Engineering is about making changes and validating them as quickly as possible. If
177+
you're spending your time _waiting_ for something, ask yourself, "is there a faster way?"
179178
</Callout>
180179

181180
## Demystifying the magic
@@ -314,9 +313,8 @@ Please delete the entire file and replace it with:
314313
(For the sharp eyes, this is on line 31 of the file).
315314

316315
<Callout>
317-
🐢 The <strong>div</strong> part of this isn't important. React looks{' '}
318-
<strong>any</strong> tag up with that id. And the specific tag isn't important
319-
either.
316+
🐢 The **div** part of this isn't important. React looks **any** tag up with that id. And the
317+
specific tag isn't important either.
320318
</Callout>
321319

322320
Save the file. Stop and restart the development server.
@@ -406,7 +404,7 @@ Clear out the file for the following:
406404
<CodeFile language="tsx" file="App.tsx">
407405
{`
408406
function App() {
409-
return <>Hello World</>
407+
return <span>Hello World</span>
410408
}\n
411409
export default App
412410
`}
@@ -424,28 +422,25 @@ export default App
424422
`import NameHere from './file'`.
425423

426424
<Callout>
427-
🐢 You no longer need to <strong>import React from 'react'</strong> in your
428-
files with React 17.{' '}
429-
<a href="https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html">
430-
Details here.
431-
</a>
425+
🐢 You no longer need to `import React from 'react'` in your files with React 17 or higher.
426+
[Details here.](https://github.com/ethanmick/ethanmick.com/pull/66/files)
432427
</Callout>
433428

434429
And that's the file! You can trim it down some more with ES 6 syntax:
435430

436431
<CodeFile language="tsx" file="App.tsx">
437432
{`
438-
export default () => <>Hello World</>
433+
export default () => <span>Hello World</span>
439434
`}
440435
</CodeFile>
441436

442437
This is as small and simple as it can get. It exports a default function that
443438
has **no** name. That function is a component, and it returns the JSX element of
444-
`<>Hello World</>`.
439+
`<span>Hello World</span>`.
445440

446441
A React component needs to return JSX element, it can't return just a regular
447442
string. This is why you can't return the literal `'Hello World`. You need to
448-
wrap it with the `<> ... </>`.
443+
wrap it with the a tag, `span` in this instance.
449444

450445
When you trim this down, it will look like this:
451446

@@ -458,9 +453,9 @@ When you trim this down, it will look like this:
458453
(Not very exciting yet. But simple!)
459454

460455
<Callout>
461-
🐢 Your linter may not like that single line. I know. It **isn't** good code.
462-
But it's short and simple, and you can explain every character. You will build
463-
it back up and understand the steps along the way.
456+
🐢 Your linter may not like that single line. I know. It **isn't** good code. But it's short and
457+
simple, and you can explain every character. You will build it back up and understand the steps
458+
along the way.
464459
</Callout>
465460

466461
Moving on.
@@ -559,7 +554,7 @@ Go back to `App.tsx` and change the content to:
559554

560555
<CodeFile language="tsx" file="App.tsx">
561556
{`
562-
const App = () => <>Hello World</>
557+
const App = () => <span>Hello World</span>
563558
export default App
564559
`}
565560
</CodeFile>

0 commit comments

Comments
 (0)