Skip to content

Commit f3b1ea3

Browse files
committed
r18 fixes
1 parent 53112f1 commit f3b1ea3

File tree

16 files changed

+103
-50
lines changed

16 files changed

+103
-50
lines changed

src/content/1/fi/osa1d.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ lang: fi
1010

1111
### Huomio Reactin versioista
1212

13-
Version 18 of React was released late March 2022. The code in material should work as it is with the new React version. However, some libraries might not yet be compatible with React 18. At the moment of writing (4th April) at least the Apollo client used in [part 8](/en/part8) does not yet work with most recent React.
13+
Reactin uusin versio 18 julkaistiin maaliskuun 2022 lopussa. Materiaalin koodin pitäisi toimia sellaisenaan uudenkin Reactin kanssa poislukien [osassa 8](/osa8) käytettävää Apollo Clientiä.
1414

15-
In case you end up in a situation where your application breaks because of library compatibly problems, <i>downgrade</i> to the older React by changing the file <i>package.json</i> as follows:
15+
Jos törmäät ongelmiin voit downgreidata projektin vanhempaan Reactiin muuttamalla tiedostoa <i>package.json</i> seuraavasti:
1616

1717
```js
1818
{
@@ -26,13 +26,13 @@ In case you end up in a situation where your application breaks because of libra
2626
}
2727
```
2828

29-
After the change is made, reinstall dependencies by running
29+
ja asentamalla muutoksen jälkeen riippuvuudet uudelleen suorittamalla komento
3030

3131
```js
3232
npm install
3333
```
3434

35-
Note that also the file <i>index.js</i> needs to be changed a bit. For React 17 it looks like
35+
Huomaa, että myös tiedosto <i>index.js</i> eroaa hieman eri Reactin versiossa. React 17:lla se näyttää seuraavalta
3636

3737
```js
3838
import ReactDOM from 'react-dom'
@@ -41,7 +41,7 @@ import App from './App'
4141
ReactDOM.render(<App />, document.getElementById('root'))
4242
```
4343

44-
but for React 18 the correct form is
44+
React 18:aa käyttäessä tiedoston muoto on seuraava:
4545

4646
```js
4747
import React from 'react'

src/content/5/en/part5b.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,8 @@ const App = () => {
374374
}
375375
```
376376

377-
<!-- Vastaava muutos voitaisiin tehdä myös kirjautumislomakkeelle, mutta jätämme sen vapaaehtoiseksi harjoitustehtäväksi. -->
378377
We could do the same for the log in form, but we'll leave that for an optional exercise.
379378

380-
<!-- Sovelluksen tämänhetkinen koodi on kokonaisuudessaan [githubissa](https://github.com/fullstack-hy2020/part2-notes/tree/part5-5), branchissa <i>part5-5</i>. -->
381379
The application code can be found from [github](https://github.com/fullstack-hy2020/part2-notes/tree/part5-5),
382380
branch <i>part5-5</i>.
383381

src/content/6/en/part6a.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ would cause the following to be printed
179179
The code of our counter application is the following. All of the code has been written in the same file, so <i>store</i> is straight available for the React-code. We will get to know better ways to structure React/Redux-code later.
180180

181181
```js
182-
import ReactDOM from 'react-dom'
182+
import React from 'react'
183+
import ReactDOM from 'react-dom/client'
184+
183185
import { createStore } from 'redux'
184186

185187
const counterReducer = (state = 0, action) => {
@@ -223,7 +225,7 @@ const App = () => {
223225
}
224226

225227
const renderApp = () => {
226-
ReactDOM.render(<App />, document.getElementById('root'))
228+
ReactDOM.createRoot(document.getElementById('root')).render(<App />)
227229
}
228230

229231
renderApp()
@@ -829,15 +831,20 @@ Next we move the _App_ component into its own file _App.js_. Let's see how this
829831
_index.js_ becomes:
830832

831833
```js
832-
import ReactDOM from 'react-dom'
834+
import React from 'react'
835+
import ReactDOM from 'react-dom/client'
836+
837+
import App from './App'
838+
839+
833840
import { createStore } from 'redux'
834841
import { Provider } from 'react-redux' // highlight-line
835842
import App from './App'
836843
import noteReducer from './reducers/noteReducer'
837844

838845
const store = createStore(noteReducer)
839846

840-
ReactDOM.render(
847+
ReactDOM.createRoot(document.getElementById('root')).render(
841848
<Provider store={store}> // highlight-line
842849
<App />
843850
</Provider>, // highlight-line

src/content/6/en/part6b.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ We can create the actual reducer for our application by combining the two existi
144144
Let's define the combined reducer in the <i>index.js</i> file:
145145

146146
```js
147-
import ReactDOM from 'react-dom'
147+
import React from 'react'
148+
import ReactDOM from 'react-dom/client'
148149
import { createStore, combineReducers } from 'redux' // highlight-line
149150
import { Provider } from 'react-redux'
150151
import App from './App'
@@ -163,14 +164,13 @@ const store = createStore(reducer)
163164

164165
console.log(store.getState())
165166

166-
ReactDOM.render(
167+
ReactDOM.createRoot(document.getElementById('root')).render(
167168
/*
168169
<Provider store={store}>
169170
<App />
170171
</Provider>,
171172
*/
172-
<div />,
173-
document.getElementById('root')
173+
<div />
174174
)
175175
```
176176

@@ -239,7 +239,7 @@ Is there a bug in our code? No. The combined reducer works in such a way that ev
239239
Let's finish the application so that it uses the combined reducer. We start by changing the rendering of the application and hooking up the store to the application in the <i>index.js</i> file:
240240

241241
```js
242-
ReactDOM.render(
242+
ReactDOM.createRoot(document.getElementById('root')).render(
243243
<Provider store={store}>
244244
<App />
245245
</Provider>,
@@ -251,8 +251,6 @@ Next, let's fix a bug that is caused by the code expecting the application store
251251

252252
![](../../images/6/7ea.png)
253253

254-
255-
<!-- Korjaus on helppo. Koska muistiinpanot ovat nyt storen kentässä <i>notes</i>, riittää pieni muutos selektorifunktioon: -->
256254
It's an easy fix. Because the notes are in the store's field <i>notes</i>, we only have to make a little change to the selector function:
257255

258256
```js
@@ -414,7 +412,8 @@ npm install @reduxjs/toolkit
414412
Next, open the <i>index.js</i> file which currently creates the Redux store. Instead of Redux's <em>createStore</em> function, let's create the store using Redux Toolkit's [configureStore](https://redux-toolkit.js.org/api/configureStore) function:
415413
416414
```js
417-
import ReactDOM from 'react-dom'
415+
import React from 'react'
416+
import ReactDOM from 'react-dom/client'
418417
import { Provider } from 'react-redux'
419418
import { configureStore } from '@reduxjs/toolkit' // highlight-line
420419
import App from './App'
@@ -433,7 +432,7 @@ const store = configureStore({
433432

434433
console.log(store.getState())
435434

436-
ReactDOM.render(
435+
ReactDOM.createRoot(document.getElementById('root')).render(
437436
<Provider store={store}>
438437
<App />
439438
</Provider>,

src/content/6/en/part6c.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,13 @@ export default store
570570
After the changes, the content of the <i>index.js</i> is the following:
571571

572572
```js
573-
import ReactDOM from 'react-dom'
573+
import React from 'react'
574+
import ReactDOM from 'react-dom/client'
574575
import { Provider } from 'react-redux'
575576
import store from './store' // highlight-line
576577
import App from './App'
577578

578-
ReactDOM.render(
579+
ReactDOM.createRoot(document.getElementById('root')).render(
579580
<Provider store={store}>
580581
<App />
581582
</Provider>,

src/content/6/fi/osa6a.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ tulostaisi
176176
Laskurisovelluksemme koodi on seuraavassa. Kaikki koodi on kirjoitettu samaan tiedostoon, joten <i>store</i> on suoraan React-koodin käytettävissä. Tutustumme React/Redux-koodin parempiin strukturointitapoihin myöhemmin.
177177

178178
```js
179-
import ReactDOM from 'react-dom'
179+
import React from 'react'
180+
import ReactDOM from 'react-dom/client'
181+
180182
import { createStore } from 'redux'
181183

182184
const counterReducer = (state = 0, action) => {
@@ -220,7 +222,7 @@ const App = () => {
220222
}
221223

222224
const renderApp = () => {
223-
ReactDOM.render(<App />, document.getElementById('root'))
225+
ReactDOM.createRoot(document.getElementById('root')).render(<App />)
224226
}
225227

226228
renderApp()
@@ -809,19 +811,23 @@ Eriytetään komponentti _App_ tiedostoon _App.js_. Tarkastellaan kuitenkin ensi
809811
Tiedosto _index.js_ näyttää seuraavalta:
810812
811813
```js
812-
import ReactDOM from 'react-dom'
814+
import React from 'react'
815+
import ReactDOM from 'react-dom/client'
816+
817+
import App from './App'
818+
819+
813820
import { createStore } from 'redux'
814821
import { Provider } from 'react-redux' // highlight-line
815822
import App from './App'
816823
import noteReducer from './reducers/noteReducer'
817824

818825
const store = createStore(noteReducer)
819826

820-
ReactDOM.render(
827+
ReactDOM.createRoot(document.getElementById('root')).render(
821828
<Provider store={store}> // highlight-line
822829
<App />
823-
</Provider>, // highlight-line
824-
document.getElementById('root')
830+
</Provider> // highlight-line
825831
)
826832
```
827833

src/content/6/fi/osa6b.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ Saamme nyt muodostettua varsinaisen reducerin yhdistämällä kaksi olemassaolev
135135
Määritellään yhdistetty reducer tiedostossa <i>index.js</i>:
136136

137137
```js
138-
import ReactDOM from 'react-dom'
138+
import React from 'react'
139+
import ReactDOM from 'react-dom/client'
139140
import { createStore, combineReducers } from 'redux' // highlight-line
140141
import { Provider } from 'react-redux'
141142
import App from './App'
@@ -154,7 +155,7 @@ const store = createStore(reducer)
154155

155156
console.log(store.getState())
156157

157-
ReactDOM.render(
158+
ReactDOM.createRoot(document.getElementById('root')).render(
158159
/*
159160
<Provider store={store}>
160161
<App />
@@ -219,7 +220,7 @@ Onko koodissa bugi? Ei. Yhdistetty reducer toimii siten, että jokainen <i>actio
219220
Viimeistellään nyt sovellus käyttämään yhdistettyä reduceria, eli palautetaan tiedostossa <i>index.js</i> suoritettava renderöinti seuravaan muotoon:
220221

221222
```js
222-
ReactDOM.render(
223+
ReactDOM.createRoot(document.getElementById('root')).render(
223224
<Provider store={store}>
224225
<App />
225226
</Provider>,
@@ -389,7 +390,8 @@ npm install @reduxjs/toolkit
389390
Avataan sen jälkeen <i>index.js</i>-tiedosto, jossa nykyinen Redux-store luodaan. Käytetään storen luonnissa Reduxin <em>createStore</em>-funktion sijaan Redux Toolkitin [configureStore](https://redux-toolkit.js.org/api/configureStore)-funktiota:
390391
391392
```js
392-
import ReactDOM from 'react-dom'
393+
import React from 'react'
394+
import ReactDOM from 'react-dom/client'
393395
import { Provider } from 'react-redux'
394396
import { configureStore } from '@reduxjs/toolkit' // highlight-line
395397
import App from './App'
@@ -408,7 +410,7 @@ const store = configureStore({
408410

409411
console.log(store.getState())
410412

411-
ReactDOM.render(
413+
ReactDOM.createRoot(document.getElementById('root')).render(
412414
<Provider store={store}>
413415
<App />
414416
</Provider>,

src/content/6/fi/osa6c.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ import { Provider } from 'react-redux'
569569
import store from './store' // highlight-line
570570
import App from './App'
571571

572-
ReactDOM.render(
572+
ReactDOM.createRoot(document.getElementById('root')).render(
573573
<Provider store={store}>
574574
<App />
575575
</Provider>,

src/content/7/en/part7a.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ The navigation bar and an application containing multiple views is very easy to
3434
Here is one way:
3535

3636
```js
37-
import { useState } from 'react'
38-
import ReactDOM from 'react-dom'
37+
import React, { useState } from 'react'
38+
import ReactDOM from 'react-dom/client'
3939

4040
const Home = () => (
4141
<div> <h2>TKTL notes app</h2> </div>
@@ -90,7 +90,7 @@ const App = () => {
9090
)
9191
}
9292

93-
ReactDOM.render(<App />, document.getElementById('root'))
93+
ReactDOM.createRoot(document.getElementById('root')).render(<App />, document.getElementById('root'))
9494
```
9595

9696
Each view is implemented as its own component. We store the view component information in the application state called <i>page</i>. This information tells us which component, representing a view, should be shown below the menu bar.
@@ -426,7 +426,7 @@ One way to do this would be to use React Router's [useMatch](https://reactrouter
426426
It is not possible to use the <i>useMatch</i> hook in the component which defines the routed part of the application. Let's move the use of the _Router_ components from _App_:
427427

428428
```js
429-
ReactDOM.render(
429+
ReactDOM.createRoot(document.getElementById('root')).render(
430430
<Router> // highlight-line
431431
<App />
432432
</Router>, // highlight-line

src/content/7/en/part7d.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ And let's turn our application into a React application by adding the familiar d
205205

206206
```js
207207
import React from 'react'
208-
import ReactDOM from 'react-dom'
208+
import ReactDOM from 'react-dom/client'
209209
import App from './App'
210210

211-
ReactDOM.render(<App />, document.getElementById('root'))
211+
ReactDOM.createRoot(document.getElementById('root')).render(<App />, document.getElementById('root'))
212212
```
213213

214214
We will also make the following changes to the <i>App.js</i> file:

0 commit comments

Comments
 (0)