@@ -8,8 +8,8 @@ We are also going to consider error messages for these form elements.
8
8
In my earlier React times, I thought it was a good idea to store fetched endpoint data directly
9
9
as component state to finally pass it down to child components.
10
10
This came with major drawbacks like bringing the state in the right format in every child component on every render cycle.
11
- Sometimes the same had to be done multiple times. Not that good for performance and
12
- [ DRY] ( https://de.wikipedia.org/wiki/Don%E2%80%99t_repeat_yourself ) .
11
+ Sometimes the same computation had to be done even multiple times. Not that good for performance and the
12
+ [ DRY] ( https://de.wikipedia.org/wiki/Don%E2%80%99t_repeat_yourself ) principle .
13
13
14
14
It got even worse when error messages had to be displayed for some form elements.
15
15
These error messages were saved in another state variable and had to be mapped to the right
@@ -20,8 +20,8 @@ computation of data can be kept to a minimum while rendering the component tree.
20
20
21
21
This goes also hand in hand with the
22
22
[ low coupling principle] ( https://stackoverflow.com/questions/14000762/what-does-low-in-coupling-and-high-in-cohesion-mean ) :
23
- Once the API changes, we only need to change the transformer function which takes in delivered data from the API
24
- and outputs the corresponding UI state.
23
+ If the API changes for any reason , we only need to change the transformer function which takes in the
24
+ delivered data from the API and outputs the corresponding UI state.
25
25
26
26
### 6.2 Defining the ` TextFieldState `
27
27
According to our learnings in the past it would be nice to have a state for every form element.
@@ -308,8 +308,8 @@ I suggest using a `data` and `onChangeData` property:
308
308
``` typescript jsx
309
309
// src/packages/core/form/TextField.tsx
310
310
311
- import { TextFieldState } from ' ./formElementState' ;
312
311
import React , { CSSProperties , FC } from ' react' ;
312
+ import { TextFieldState } from ' ./formElementState' ;
313
313
import { TextField as MuiTextField , InputProps , FormControl } from ' @mui/material' ;
314
314
import { Messages } from ' ./Messages' ;
315
315
@@ -384,7 +384,7 @@ Let's do the same for the checkbox form element:
384
384
// src/packages/core/form/Checkbox.tsx
385
385
386
386
import React , { FC , ReactNode } from ' react' ;
387
- import { CheckboxState } from ' @packages/core/form ' ;
387
+ import { CheckboxState } from ' ./formElementState ' ;
388
388
import { Checkbox as MuiCheckbox , FormControl , FormControlLabel } from ' @mui/material' ;
389
389
import { Messages } from ' ./Messages' ;
390
390
0 commit comments