-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-FunctionWithContext.jsx
37 lines (34 loc) · 1.01 KB
/
07-FunctionWithContext.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React, { useState, useContext } from 'react';
import Row from './Row';
import { ThemeContext, LocaleContext } from './context';
export default function Greeting(props) {
const [name, setName] = useState('Mary');
const [name, setSurname] = useState('Poppins');
const theme = useContext(ThemeContext);
const locale = useContext(LocaleContext);
function handleNameChange(e) {
setName(e.target.value);
}
function handleSurnameChange(e) {
setSurname(e.target.value);
}
return (
<section className={theme}>
<Row label="Name">
<input
value={name}
onChange={handleNameChange}
/>
</Row>
<Row label="Surname">
<input
value={surname}
onChange={handleSurnameChange}
/>
</Row>
<Row label="Language">
{locale}
</Row>
</section>
)
}