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
@@ -497,8 +497,8 @@ don't write more code but rather find and fix the problem **immediately**. There
497
497
Old-school, print-based debugging is always a good idea. If the component
498
498
499
499
```js
500
-
constButton= ({ handleClick, text }) => (
501
-
<button onClick={handleClick}>
500
+
constButton= ({ onClick, text }) => (
501
+
<button onClick={onClick}>
502
502
{text}
503
503
</button>
504
504
)
@@ -509,9 +509,9 @@ is not working as intended, it's useful to start printing its variables out to t
509
509
```js
510
510
constButton= (props) => {
511
511
console.log(props) // highlight-line
512
-
const { handleClick, text } = props
512
+
const { onClick, text } = props
513
513
return (
514
-
<button onClick={handleClick}>
514
+
<button onClick={onClick}>
515
515
{text}
516
516
</button>
517
517
)
@@ -1030,31 +1030,31 @@ Let's extract the button into its own component:
1030
1030
1031
1031
```js
1032
1032
constButton= (props) => (
1033
-
<button onClick={props.handleClick}>
1033
+
<button onClick={props.onClick}>
1034
1034
{props.text}
1035
1035
</button>
1036
1036
)
1037
1037
```
1038
1038
1039
-
The component gets the event handler function from the _handleClick_ prop, and the text of the button from the _text_ prop. Lets use the new component:
1039
+
The component gets the event handler function from the _onClick_ prop, and the text of the button from the _text_ prop. Lets use the new component:
Using the <i>Button</i> component is simple, although we have to make sure that we use the correct attribute names when passing props to the component.
Copy file name to clipboardExpand all lines: src/content/1/fi/osa1c.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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 _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.
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 eli on muotoa _onSomething_.
625
625
626
626
### Tilan muutos aiheuttaa uudelleenrenderöitymisen
@@ -493,8 +491,8 @@ Jos ja kun koodi ei käänny eli selaimessa alkaa näkyä punaista
493
491
Vanha kunnon printtaukseen perustuva debuggaus on monesti toimiva tapa. Eli jos esim. komponentissa
494
492
495
493
```js
496
-
constButton= ({ handleClick, text }) => (
497
-
<button onClick={handleClick}>
494
+
constButton= ({ onClick, text }) => (
495
+
<button onClick={onClick}>
498
496
{text}
499
497
</button>
500
498
)
@@ -505,9 +503,9 @@ olisi ongelma, kannattaa komponentista alkaa printtailla konsoliin. Pystyäksemm
505
503
```js
506
504
constButton= (props) => {
507
505
console.log(props) // highlight-line
508
-
const { handleClick, text } = props
506
+
const { onClick, text } = props
509
507
return (
510
-
<button onClick={handleClick}>
508
+
<button onClick={onClick}>
511
509
{text}
512
510
</button>
513
511
)
@@ -1022,31 +1020,31 @@ Eriytetään vielä painike omaksi komponentikseen:
1022
1020
1023
1021
```js
1024
1022
constButton= (props) => (
1025
-
<button onClick={props.handleClick}>
1023
+
<button onClick={props.onClick}>
1026
1024
{props.text}
1027
1025
</button>
1028
1026
)
1029
1027
```
1030
1028
1031
-
Komponentti saa siis propsina _handleClick_ tapahtumankäsittelijän ja propsina _text_ merkkijonon, jonka se renderöi painikkeen tekstiksi. Komponenttia käytetään seuraavasti:
1029
+
Komponentti saa siis propsina _onClick_ tapahtumankäsittelijän ja propsina _text_ merkkijonon, jonka se renderöi painikkeen tekstiksi. Komponenttia käytetään seuraavasti:
Komponentin <i>Button</i> käyttö on helppoa, mutta on toki pidettävä huolta siitä, että komponentille annettavat propsit on nimetty niin kuin komponentti olettaa:
1048
1046
1049
-

1047
+

1050
1048
1051
1049
### Älä määrittele komponenttia komponentin sisällä
1052
1050
@@ -1057,7 +1055,7 @@ Määritellään uusi komponentti <i>App</i>-komponentin sisällä:
0 commit comments