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
Copy file name to clipboardExpand all lines: src/content/1/en/part1c.md
+2-25Lines changed: 2 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -628,10 +628,10 @@ const App = () => {
628
628
629
629
Since we now have an easily reusable <i>Button</i> component, we've also implemented new functionality into our application by adding a button that can be used to decrement the counter.
630
630
631
-
The event handler is passed to the <i>Button</i> component through the _onClick_ prop. The name of the prop itself is not that significant, but our naming choice wasn't completely random.
631
+
The event handler is passed to the <i>Button</i> component through the _onClick_ prop. When creating your own components, you can theoretically choose the prop name freely. However, our naming choice for the event handler was not entirely arbitrary.
632
632
633
633
React's own official [tutorial](https://react.dev/learn/tutorial-tic-tac-toe) suggests:
634
-
"In React, it’s conventional to use onSomething names for props which take functions which handle events and handleSomething for the actual function definitions which handle those events."
634
+
"In React, it’s conventional to use _onSomething_ names for props which take functions which handle events and handleSomething for the actual function definitions which handle those events."
635
635
636
636
### Changes in state cause re-rendering
637
637
@@ -729,11 +729,6 @@ const Button = (props) => {
729
729
730
730
We can use destructuring to get only the required fields from <i>props</i>, and use the more compact form of arrow functions:
731
731
732
-
**NB**: While building your own components, you can name their event handler props anyway you like, for this you can refer to the react's documentation on [Naming event handler props](https://react.dev/learn/responding-to-events#naming-event-handler-props). It goes as following:
733
-
734
-
> By convention, event handler props should start with `on`, followed by a capital letter.
735
-
For example, the Button component’s `onClick` prop could have been called `onSmash`:
Copy file name to clipboardExpand all lines: src/content/1/fi/osa1c.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -580,7 +580,7 @@ Tehdään seuraavaksi napeille tarkoitettu komponentti <i>Button</i>. Napille on
580
580
```js
581
581
constButton= (props) => {
582
582
return (
583
-
<button onClick={props.handleClick}>
583
+
<button onClick={props.onClick}>
584
584
{props.text}
585
585
</button>
586
586
)
@@ -602,15 +602,15 @@ const App = () => {
602
602
<Display counter={counter}/>
603
603
// highlight-start
604
604
<Button
605
-
handleClick={increaseByOne}
605
+
onClick={increaseByOne}
606
606
text='plus'
607
607
/>
608
608
<Button
609
-
handleClick={setToZero}
609
+
onClick={setToZero}
610
610
text='zero'
611
611
/>
612
612
<Button
613
-
handleClick={decreaseByOne}
613
+
onClick={decreaseByOne}
614
614
text='minus'
615
615
/>
616
616
// highlight-end
@@ -621,7 +621,7 @@ const App = () => {
621
621
622
622
Koska meillä on nyt uudelleenkäytettävä komponentti <i>Button</i>, sovellukselle on lisätty uutena toiminnallisuutena nappi, jolla laskurin arvoa voi vähentää.
623
623
624
-
Tapahtumankäsittelijä välitetään napeille propsin _handleClick_ välityksellä. Propsin nimellä ei ole sinänsä merkitystä, mutta valinta ei ollut sattumanvarainen, sillä esim. Reactin [tutoriaali](https://react.dev/learn/tutorial-tic-tac-toe) suosittelee tätä konventiota.
624
+
Tapahtumankäsittelijä välitetään napeille propsin _onClick_ välityksellä. Omia komponentteja luotaessa propsin nimen voi periaatteessa valita täysin vapaasti, mutta esim. Reactin [tutoriaali](https://react.dev/learn/responding-to-events#naming-event-handler-props) suosittelee, että tapahtumankäsittelijän sisältävän propsin nimi alkaa etuliitteellä _on_ ja jatkuu isolla kirjaimella.
625
625
626
626
### Tilan muutos aiheuttaa uudelleenrenderöitymisen
0 commit comments