-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
74 lines (64 loc) · 1.84 KB
/
App.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import "./App.css";
import useUrlState from "./useUrlState";
import useNavigate from "./useUrlState/useNavigate";
// Util
const noop = () => {};
const Button = ({ children, onClick = noop, ...props }) => {
return (
<button className="button" onClick={onClick} {...props}>
{children}
</button>
);
};
// Data
const languages = ["React", "Svelte", "Visual Basic"];
const animals = ["Cat", "Dog", "Rock"];
function App() {
const [urlState, setUrlState] = useUrlState({ language: "React" });
const navigate = useNavigate();
const { language = "", pet = "" } = urlState;
const setLanguage = (lang) => {
setUrlState({
language: lang,
});
};
const setPet = (animal) => {
setUrlState((curState) => ({
...curState,
pet: animal,
}));
};
return (
<div className="App">
<div className="grid-container">
<div className="url-text">{window.location.toString()}</div>
<div className="input-label">Set</div>
<div className="output-label">Get</div>
<div className="language-buttons">
{languages.map((lang) => (
<Button key={lang} onClick={() => setLanguage(lang)}>
{lang}
</Button>
))}
<Button onClick={() => setLanguage(null)}>Clear</Button>
</div>
<a className="language-text link" href="/">
{language}
</a>
<div className="animal-buttons">
{animals.map((animal) => (
<Button key={animal} onClick={() => setPet(animal)}>
{animal}
</Button>
))}
<Button onClick={() => setPet(null)}>Clear</Button>
</div>
<a className="animal-text link" href="/">
{pet}
</a>
<Button onClick={() => navigate("/")}>Clear All</Button>
</div>
</div>
);
}
export default App;