Skip to content

Commit 2ce0d93

Browse files
committed
Clarify part2e about defining a component in a separate file
1 parent 994a010 commit 2ce0d93

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/content/2/en/part2e.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ If you now add other <i>li</i> elements to the application, they will not be aff
108108

109109
### Improved error message
110110

111-
We previously implemented the error message that was displayed when the user tried to toggle the importance of a deleted note with the <em>alert</em> method. Let's implement the error message as its own React component.
111+
We previously implemented the error message that was displayed when the user tried to toggle the importance of a deleted note with the <em>alert</em> method. Let's implement the error message as its own React component in the file <i>src/components/Notification.jsx</i>.
112112

113113
The component is quite simple:
114114

@@ -119,11 +119,12 @@ const Notification = ({ message }) => {
119119
}
120120

121121
return (
122-
<div className='error'>
122+
<div className="error">
123123
{message}
124124
</div>
125125
)
126126
}
127+
127128
export default Notification
128129
```
129130

src/content/2/fi/osa2e.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Jos nyt lisäät sovellukseen muita li-elementtejä, ne eivät saa muistiinpanoi
108108

109109
### Parempi virheilmoitus
110110

111-
Aiemmin toteutimme olemassa olemattoman muistiinpanon tärkeyden muutokseen liittyvän virheilmoituksen <em>alert</em>-metodilla. Toteutetaan se nyt Reactilla omana komponenttinaan.
111+
Aiemmin toteutimme olemassa olemattoman muistiinpanon tärkeyden muutokseen liittyvän virheilmoituksen <em>alert</em>-metodilla. Toteutetaan se nyt Reactilla omana komponenttinaan tiedostossa <i>src/components/Notification.jsx</i>.
112112

113113
Komponentti on yksinkertainen:
114114

@@ -124,13 +124,20 @@ const Notification = ({ message }) => {
124124
</div>
125125
)
126126
}
127+
128+
export default Notification
127129
```
128130

129131
Jos propsin <em>message</em> arvo on <em>null</em>, ei renderöidä mitään. Muussa tapauksessa renderöidään viesti div-elementtiin. Elementille on liitetty tyylien lisäämistä varten luokka <i>error</i>.
130132

131133
Lisätään komponentin <i>App</i> tilaan kenttä <i>errorMessage</i> virheviestiä varten. Laitetaan kentälle heti jotain sisältöä, jotta pääsemme testaamaan komponenttia:
132134

133135
```js
136+
import { useState, useEffect } from 'react'
137+
import Note from './components/Note'
138+
import noteService from './services/notes'
139+
import Notification from './components/Notification' // highlight-line
140+
134141
const App = () => {
135142
const [notes, setNotes] = useState([])
136143
const [newNote, setNewNote] = useState('')

0 commit comments

Comments
 (0)