Skip to content

Commit 6906275

Browse files
committed
react 18
1 parent 3cfa89a commit 6906275

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

src/components/layout.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import PropTypes from 'prop-types';
99
class Layout extends Component {
1010
state = {
1111
siteLanguage: 'fi',
12+
visible: true,
1213
};
1314

1415
componentDidMount() {
@@ -18,18 +19,85 @@ class Layout extends Component {
1819
: window.location.pathname.indexOf('/zh') > -1
1920
? 'zh'
2021
: 'fi';
22+
2123
this.setState({
2224
siteLanguage: siteLanguage,
25+
visible: true,
26+
});
27+
}
28+
29+
hideNote() {
30+
console.log('yes');
31+
this.setState({
32+
siteLanguage: this.state.siteLanguage,
33+
visible: false,
2334
});
2435
}
2536

2637
render() {
27-
const { siteLanguage } = this.state;
38+
const { siteLanguage, visible } = this.state;
39+
40+
const style = {
41+
padding: 10,
42+
borderStyle: 'solid',
43+
borderWidth: 2,
44+
marginLeft: 80,
45+
marginRight: 80,
46+
position: 'sticky',
47+
top: 100,
48+
left: 40,
49+
display: 'flex',
50+
flexWrap: 'wrap',
51+
flexDirection: 'row',
52+
alignContent: 'space-between',
53+
backgroundColor: '#E8E8E8',
54+
zIndex: 2147483647,
55+
};
56+
57+
const linkStyle = {
58+
color: 'grey',
59+
textDecoration: 'underline',
60+
};
61+
62+
const textStyle = {
63+
flex: 90,
64+
};
65+
66+
const buttonDiv = {
67+
flex: 10,
68+
textAlign: 'right',
69+
};
70+
71+
const buttonStyle = {
72+
outline: 'none',
73+
backgroundColor: 'transparent',
74+
border: 'none',
75+
};
76+
77+
console.log(this.state);
2878

2979
return (
3080
<div className="main-wrapper">
3181
<Header lang={siteLanguage} />
3282

83+
{visible && (
84+
<div style={style}>
85+
<div stule={textStyle}>
86+
Note that some libraries might not work with the new React version
87+
18. If you run in trouble with library compatibility, read{' '}
88+
<a href="/en/part1/a_more_complex_state_debugging_react_apps#a-note-on-react-version">
89+
<span style={linkStyle}>this</span>
90+
</a>
91+
.
92+
</div>
93+
<div style={buttonDiv}>
94+
<button style={buttonStyle} onClick={() => this.hideNote()}>
95+
x
96+
</button>
97+
</div>
98+
</div>
99+
)}
100+
33101
{this.props.children}
34102
</div>
35103
);

src/content/1/en/part1d.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ lang: en
77

88
<div class="content">
99

10+
### A note on React version
11+
12+
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+
14+
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>pacgage.json</i> as follows:
15+
16+
```js
17+
{
18+
"dependencies": {
19+
"react": "^17.0.2", // highlight-line
20+
"react-dom": "^17.0.2", // highlight-line
21+
"react-scripts": "5.0.0",
22+
"web-vitals": "^2.1.4"
23+
},
24+
// ...
25+
}
26+
```
27+
28+
After the change is made, reinstall dependencies by running
29+
30+
```js
31+
npm install
32+
```
33+
1034
### Complex state
1135

1236
In our previous example the application state was simple as it was comprised of a single integer. What if our application requires a more complex state?
@@ -1013,7 +1037,8 @@ You may find the following links useful:
10131037
</div>
10141038

10151039
<div class="tasks">
1016-
<h3>Exercises 1.6.-1.14.</h3>
1040+
1041+
<h3>Exercises 1.6.-1.14.</h3>
10171042

10181043
Submit your solutions to the exercises by first pushing your code to GitHub and then marking the completed exercises into the [exercise submission system](https://studies.cs.helsinki.fi/stats/courses/fullstackopen).
10191044

@@ -1029,7 +1054,7 @@ In some situations you may also have to run the command below from the root of t
10291054
rm -rf node_modules/ && npm i
10301055
```
10311056

1032-
<h4> 1.6: unicafe step1</h4>
1057+
<h4> 1.6: unicafe step1</h4>
10331058

10341059
Like most companies, [Unicafe](https://www.unicafe.fi/#/9/4) 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>.
10351060

0 commit comments

Comments
 (0)