Skip to content

Commit 6bc3dd0

Browse files
committed
tweaks part 5ab
1 parent e6475e4 commit 6bc3dd0

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/content/5/en/part5b.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,11 @@ The application code can be found on [GitHub](https://github.com/fullstack-hy202
358358

359359
Our current implementation is quite good; it has one aspect that could be improved.
360360

361-
After a new note is created, it would make sense to hide the new note form. Currently, the form stays visible. There is a slight problem with hiding the form. The visibility is controlled with the <i>visible</i> state variable inside of the <i>Togglable</i> component. How can we access it outside of the component?
361+
After a new note is created, it would make sense to hide the new note form. Currently, the form stays visible. There is a slight problem with hiding the form. The visibility is controlled with the <i>visible</i> state variable inside of the <i>Togglable</i> component.
362362

363-
There are many ways to implement closing the form from the parent component, but let's use the [ref](https://react.dev/learn/referencing-values-with-refs) mechanism of React, which offers a reference to the component.
363+
One solution to this would be to move control of the Togglable component's state outside the component. However, we won't do that now, because we want the component to be responsible for its own state. So we have to find another solution, and find a mechanism to change the state of the component externally.
364+
365+
There are several different ways to implement access to a component's functions from outside the component, but let's use the [ref](https://react.dev/learn/referencing-values-with-refs) mechanism of React, which offers a reference to the component.
364366

365367
Let's make the following changes to the <i>App</i> component:
366368

@@ -706,12 +708,6 @@ In part 3 we configured the [ESlint](/en/part3/validation_and_es_lint#lint) code
706708

707709
Vite has installed ESlint to the project by default, so all that's left for us to do is define our desired configuration in the <i>.eslintrc.cjs</i> file.
708710

709-
Next, we will start testing the frontend and in order to avoid undesired and irrelevant linter errors we will install the [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest) package:
710-
711-
```bash
712-
npm install --save-dev eslint-plugin-jest
713-
```
714-
715711
Let's create a <i>.eslintrc.cjs</i> file with the following contents:
716712

717713
```js
@@ -720,7 +716,6 @@ module.exports = {
720716
env: {
721717
browser: true,
722718
es2020: true,
723-
"jest/globals": true
724719
},
725720
extends: [
726721
'eslint:recommended',
@@ -731,7 +726,7 @@ module.exports = {
731726
ignorePatterns: ['dist', '.eslintrc.cjs'],
732727
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
733728
settings: { react: { version: '18.2' } },
734-
plugins: ['react-refresh', 'jest'],
729+
plugins: ['react-refresh'],
735730
rules: {
736731
"indent": [
737732
"error",

src/content/5/fi/osa5b.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ Sovelluksen tämänhetkinen koodi on kokonaisuudessaan [GitHubissa](https://gith
362362

363363
### ref eli viite komponenttiin
364364

365-
Ratkaisu on melko hyvä, mutta haluamme kuitenkin parantaa sitä. Kun uusi muistiinpano luodaan, olisi loogista jos luomislomake menisi piiloon. Nyt lomake pysyy näkyvillä. Lomakkeen piilottamiseen sisältyy kuitenkin pieni ongelma, sillä näkyvyyttä kontrolloidaan <i>Togglable</i>-komponentin tilassa olevalla muuttujalla <i>visible</i>. Miten pääsemme tilaan käsiksi komponentin ulkopuolelta?
365+
Ratkaisu on melko hyvä, mutta haluamme kuitenkin parantaa sitä. Kun uusi muistiinpano luodaan, olisi loogista jos luomislomake menisi piiloon. Nyt lomake pysyy näkyvillä. Lomakkeen piilottamiseen sisältyy kuitenkin pieni ongelma, sillä näkyvyyttä kontrolloidaan <i>Togglable</i>-komponentin tilassa olevalla muuttujalla <i>visible</i>. Eräs ratkaisu tähän olisi siirtää Togglable-komponentin tilan kontrollointi komponentin ulkopuolelle. Emme kuitenkaan nyt tee sitä, sillä haluamme että komponentti on itse vastuussa tilastaan. Meidän on siis etsittävä jokin muu ratkaisu, ja löydettävä mekanismi komponentin tilan muuttamiseen ulkopuolelta käsin.
366366

367367
On useita erilaisia tapoja toteuttaa pääsy komponentin funktioihin sen ulkopuolelta. Käytetään nyt Reactin [ref](https://react.dev/learn/referencing-values-with-refs)-mekanismia, joka tarjoaa eräänlaisen viitteen komponenttiin.
368368

@@ -708,11 +708,6 @@ Konfiguroimme osassa 3 koodin tyylistä huolehtivan [ESLintin](/osa3/validointi_
708708
709709
Vite on asentanut projektille ESLintin valmiiksi, joten ei tarvita muuta kuin muokata tiedostossa <i>.eslintrc.cjs</i> oleva konfiguraatio halutun kaltaiseksi.
710710
711-
Aloitamme seuraavaksi testaamisen, ja jotta pääsemme eroon testeissä olevista turhista huomautuksista asennetaan plugin [eslint-jest-plugin](https://www.npmjs.com/package/eslint-plugin-jest):
712-
713-
```js
714-
npm install --save-dev eslint-plugin-jest
715-
```
716711
717712
Muutetaan tiedoston <i>.eslintrc.cjs</i> sisältöä seuraavasti:
718713
@@ -722,7 +717,6 @@ module.exports = {
722717
env: {
723718
browser: true,
724719
es2020: true,
725-
"jest/globals": true
726720
},
727721
extends: [
728722
'eslint:recommended',
@@ -733,7 +727,7 @@ module.exports = {
733727
ignorePatterns: ['dist', '.eslintrc.cjs'],
734728
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
735729
settings: { react: { version: '18.2' } },
736-
plugins: ['react-refresh', 'jest'],
730+
plugins: ['react-refresh'],
737731
rules: {
738732
"indent": [
739733
"error",
@@ -772,7 +766,7 @@ Tehdään projektin juureen tiedosto [.eslintignore](https://eslint.org/docs/use
772766
773767
```bash
774768
node_modules
775-
build
769+
dist
776770
.eslintrc.cjs
777771
```
778772

0 commit comments

Comments
 (0)