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
However, __don't__ do this. As mentioned previously, the state of React components like _allClicks_ must not be mutated directly. Even if mutating state appears to work in some cases, it can lead to problems that are very hard to debug.
227
+
However, __don't__ do this. As mentioned previously, the state of React components, like _allClicks_, must not be mutated directly. Even if mutating state appears to work in some cases, it can lead to problems that are very hard to debug.
228
228
229
229
Let's take a closer look at how the clicking is rendered to the page:
230
230
@@ -244,7 +244,7 @@ const App = () => {
244
244
}
245
245
```
246
246
247
-
We call the [join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) method on the _allClicks_ array that joins all the items into a single string, separated by the string passed as the function parameter, which in our case is an empty space.
247
+
We call the [join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) method on the _allClicks_ array, that joins all the items into a single string, separated by the string passed as the function parameter, which in our case is an empty space.
248
248
249
249
### Update of the state is asynchronous
250
250
@@ -476,7 +476,7 @@ If and when your code fails to compile and your browser lights up like a Christm
476
476

477
477
478
478
don't write more code but rather find and fix the problem **immediately**. There has yet to be a moment in the history of coding where code that fails to compile would miraculously start working after writing large amounts of additional code. I highly doubt that such an event will transpire during this course either.
479
-
479
+
480
480
Old-school, print-based debugging is always a good idea. If the component
481
481
482
482
```js
@@ -1134,29 +1134,29 @@ Personally, I mainly use Copilot, which integrates seamlessly with VS Code thank
1134
1134
1135
1135
Copilot is useful in a wide variety of scenarios. Copilot can be asked to generate code for an open file by describing the desired functionality in text:
1136
1136
1137
-

1137
+

1138
1138
1139
1139
If the code looks good, Copilot adds it to the file:
1140
1140
1141
-

1141
+

1142
1142
1143
1143
In the case of our example, Copilot only created a button, the event handler _handleResetClick_ is undefined.
1144
1144
1145
1145
An event handler may also be generated. By writing the first line of the function, Copilot offers the functionality to be generated:
In Copilot's chat window, it is possible to ask for an explanation of the function of the painted code area:
1150
1150
1151
-

1151
+

1152
1152
1153
1153
Copilot is also useful in error situations, by copying the error message into Copilot's chat, you will get an explanation of the problem and a suggested fix:
1154
1154
1155
-

1155
+

1156
1156
1157
1157
Copilot's chat also enables the creation of larger set of functionality
1158
1158
1159
-

1159
+

1160
1160
1161
1161
The degree of usefulness of the hints provided by Copilot and other language models varies. Perhaps the biggest problem with language models is [hallucination](https://en.wikipedia.org/wiki/Hallucination_(artificial_intelligence)), they sometimes generate completely convincing-looking answers, which, however, are completely wrong. When programming, of course, the hallucinated code is often caught quickly if the code does not work. More problematic situations are those where the code generated by the language model seems to work, but it contains more difficult to detect bugs or e.g. security vulnerabilities.
1162
1162
@@ -1168,7 +1168,7 @@ The rapid development of language models puts the student of programming in a ch
1168
1168
1169
1169
At this point, it is worth remembering the old wisdom of [Brian Kerningham](https://en.wikipedia.org/wiki/Brian_Kernighan), the developer of the programming language C:
1170
1170
1171
-

1171
+

1172
1172
1173
1173
In other words, since debugging is twice as difficult as programming, it is not worth programming such code that you can only barely understand. How can debugging be even possible in a situation where programming is outsourced to a language model and the software developer does not understand the debugged code at all?
1174
1174
@@ -1200,7 +1200,7 @@ If and <i>when</i> you encounter an error message
1200
1200
1201
1201
keep in mind the things told [here](/en/part1/introduction_to_react#do-not-render-objects).
1202
1202
1203
-
<h4> 1.6: unicafe step1</h4>
1203
+
<h4> 1.6: unicafe step 1</h4>
1204
1204
1205
1205
Like most companies, the student restaurant of the University of Helsinki [Unicafe](https://www.unicafe.fi) collects feedback from its customers. Your task is to implement a web application for collecting customer feedback. There are only three options for feedback: <i>good</i>, <i>neutral</i>, and <i>bad</i>.
1206
1206
@@ -1242,13 +1242,13 @@ const App = () => {
1242
1242
exportdefaultApp
1243
1243
```
1244
1244
1245
-
<h4>1.7: unicafe step2</h4>
1245
+
<h4>1.7: unicafe step 2</h4>
1246
1246
1247
1247
Expand your application so that it shows more statistics about the gathered feedback: the total number of collected feedback, the average score (good: 1, neutral: 0, bad: -1) and the percentage of positive feedback.
1248
1248
1249
1249

1250
1250
1251
-
<h4>1.8: unicafe step3</h4>
1251
+
<h4>1.8: unicafe step 3</h4>
1252
1252
1253
1253
Refactor your application so that displaying the statistics is extracted into its own <i>Statistics</i> component. The state of the application should remain in the <i>App</i> root component.
1254
1254
@@ -1276,13 +1276,13 @@ const App = () => {
1276
1276
}
1277
1277
```
1278
1278
1279
-
<h4>1.9: unicafe step4</h4>
1279
+
<h4>1.9: unicafe step 4</h4>
1280
1280
1281
1281
Change your application to display statistics only once feedback has been gathered.
1282
1282
1283
1283

1284
1284
1285
-
<h4>1.10: unicafe step5</h4>
1285
+
<h4>1.10: unicafe step 5</h4>
1286
1286
1287
1287
Let's continue refactoring the application. Extract the following two components:
The application's state should still be kept in the root <i>App</i> component.
1311
1311
1312
-
<h4>1.11*: unicafe step6</h4>
1312
+
<h4>1.11*: unicafe step 6</h4>
1313
1313
1314
1314
Display the statistics in an HTML [table](https://developer.mozilla.org/en-US/docs/Learn/HTML/Tables/Basics), so that your application looks roughly like this:
1315
1315
@@ -1321,11 +1321,11 @@ Remember to keep your console open at all times. If you see this warning in your
1321
1321
1322
1322
Then perform the necessary actions to make the warning disappear. Try pasting the error message into a search engine if you get stuck.
1323
1323
1324
-
<i>Typical source of an error _Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist._ is Chrome extension. Try going to _chrome://extensions/_ and try disabling them one by one and refreshing React app page; the error should eventually disappear.</i>
1324
+
<i>Typical source of an error _Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist._ is from a Chrome extension. Try going to _chrome://extensions/_ and try disabling them one by one and refreshing React app page; the error should eventually disappear.</i>
1325
1325
1326
1326
**Make sure that from now on you don't see any warnings in your console!**
1327
1327
1328
-
<h4>1.12*: anecdotes step1</h4>
1328
+
<h4>1.12*: anecdotes step 1</h4>
1329
1329
1330
1330
The world of software engineering is filled with [anecdotes](http://www.comp.nus.edu.sg/~damithch/pages/SE-quotes.htm) that distill timeless truths from our field into short one-liners.
1331
1331
@@ -1366,7 +1366,7 @@ Your finished application could look something like this:
1366
1366
1367
1367

1368
1368
1369
-
<h4>1.13*: anecdotes step2</h4>
1369
+
<h4>1.13*: anecdotes step 2</h4>
1370
1370
1371
1371
Expand your application so that you can vote for the displayed anecdote.
1372
1372
@@ -1396,7 +1396,7 @@ copy[2] += 1
1396
1396
1397
1397
Using an array might be the simpler choice in this case. Searching the Internet will provide you with lots of hints on how to [create a zero-filled array of the desired length](https://stackoverflow.com/questions/20222501/how-to-create-a-zero-filled-javascript-array-of-arbitrary-length/22209781).
1398
1398
1399
-
<h4>1.14*: anecdotes step3</h4>
1399
+
<h4>1.14*: anecdotes step 3</h4>
1400
1400
1401
1401
Now implement the final version of the application that displays the anecdote with the largest number of votes:
0 commit comments