Skip to content

Commit c5251a4

Browse files
committed
Use concise arrow function syntax in button component
1 parent acae3f0 commit c5251a4

File tree

4 files changed

+7
-39
lines changed

4 files changed

+7
-39
lines changed

src/content/1/en/part1c.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -729,16 +729,6 @@ const Button = (props) => {
729729
730730
We can use destructuring to get only the required fields from <i>props</i>, and use the more compact form of arrow functions:
731731
732-
```js
733-
const Button = ({ onClick, text }) => (
734-
<button onClick={onClick}>
735-
{text}
736-
</button>
737-
)
738-
```
739-
740-
Or, similar to the Display example, you can further optimize the Button component to a single line by removing the parentheses and formatting it as follows:
741-
742732
```js
743733
const Button = ({ onClick, text }) => <button onClick={onClick}>{text}</button>
744734
```

src/content/1/en/part1d.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,7 @@ const History = (props) => {
427427
)
428428
}
429429

430-
// highlight-start
431-
const Button = ({ onClick, text }) => (
432-
<button onClick={onClick}>
433-
{text}
434-
</button>
435-
)
436-
// highlight-end
430+
const Button = ({ onClick, text }) => <button onClick={onClick}>{text}</button> // highlight-line
437431

438432
const App = () => {
439433
const [left, setLeft] = useState(0)
@@ -497,11 +491,7 @@ don't write more code but rather find and fix the problem **immediately**. There
497491
Old-school, print-based debugging is always a good idea. If the component
498492

499493
```js
500-
const Button = ({ onClick, text }) => (
501-
<button onClick={onClick}>
502-
{text}
503-
</button>
504-
)
494+
const Button = ({ onClick, text }) => <button onClick={onClick}>{text}</button>
505495
```
506496

507497
is not working as intended, it's useful to start printing its variables out to the console. In order to do this effectively, we must transform our function into the less compact form and receive the entire props object without destructuring it immediately:

src/content/1/fi/osa1c.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,9 @@ const Button = (props) => {
715715
Destrukturoidaan <i>props</i>:ista tarpeelliset kentät ja käytetään nuolifunktioiden tiiviimpää muotoa:
716716
717717
```js
718-
const Button = ({ onClick, text }) => (
719-
<button onClick={onClick}>
720-
{text}
721-
</button>
722-
)
718+
const Button = ({ onClick, text }) => <button onClick={onClick}>{text}</button>
723719
```
724720
721+
Koska komponentti sisältää vain _return_-lauseen, on tiiviin nuolifunktiosyntaksin käyttö mahdollista.
722+
725723
</div>

src/content/1/fi/osa1d.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,7 @@ const History = (props) => {
421421
)
422422
}
423423

424-
// highlight-start
425-
const Button = ({ onClick, text }) => (
426-
<button onClick={onClick}>
427-
{text}
428-
</button>
429-
)
430-
// highlight-end
424+
const Button = ({ onClick, text }) => <button onClick={onClick}>{text}</button> // highlight-line
431425

432426
const App = () => {
433427
const [left, setLeft] = useState(0)
@@ -491,11 +485,7 @@ Jos ja kun koodi ei käänny eli selaimessa alkaa näkyä punaista
491485
Vanha kunnon printtaukseen perustuva debuggaus on monesti toimiva tapa. Eli jos esim. komponentissa
492486

493487
```js
494-
const Button = ({ onClick, text }) => (
495-
<button onClick={onClick}>
496-
{text}
497-
</button>
498-
)
488+
const Button = ({ onClick, text }) => <button onClick={onClick}>{text}</button>
499489
```
500490

501491
olisi ongelma, kannattaa komponentista alkaa printtailla konsoliin. Pystyäksemme printtaamaan tulee funktio muuttaa pitempään muotoon ja propsit kannattaa kenties vastaanottaa ilman destrukturointia:

0 commit comments

Comments
 (0)