Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 45a8e13

Browse files
学习hook-state
1 parent da9abd0 commit 45a8e13

File tree

5 files changed

+94
-16
lines changed

5 files changed

+94
-16
lines changed

‎src/App.js‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
import logo from './logo.svg';
2-
import './App.css';
1+
import "./App.css";
2+
import List from "./components/List";
3+
import Count from "./components/Count";
34

45
function App() {
6+
const list = ["Vue", "React", "Angular"];
57
return (
68
<div className="App">
7-
<header className="App-header">
8-
<img src={logo} className="App-logo" alt="logo" />
9-
<p>
10-
Edit <code>src/App.js</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
Learn React
19-
</a>
20-
</header>
9+
<List data={list}></List>
10+
<Count></Count>
2111
</div>
2212
);
2313
}

‎src/components/Count/index.css‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.count-box{
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
6+
}
7+
.content{
8+
width: 50px;
9+
height: 50px;
10+
line-height: 50px;
11+
text-align: center;
12+
}
13+
.btn{
14+
width: 50px;
15+
height: 50px;
16+
cursor: pointer;
17+
border-radius: 50%;
18+
font-size: 30px;
19+
text-align: center;
20+
border: 1px solid #eee;
21+
box-sizing: border-box;
22+
}

‎src/components/Count/index.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import "./index.css";
2+
import { useState } from "react";
3+
const Count = () => {
4+
const [count, setcount] = useState(0);
5+
6+
function add() {
7+
setcount(count + 1);
8+
}
9+
10+
function reduce() {
11+
setcount(count - 1);
12+
}
13+
14+
return (
15+
<div className="count-box">
16+
<span className="btn" onClick={reduce}>
17+
-
18+
</span>
19+
<span className="content">{count}</span>
20+
<span className="btn" onClick={add}>
21+
+
22+
</span>
23+
</div>
24+
);
25+
};
26+
27+
export default Count;

‎src/components/List/index.css‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.box{
2+
width: 40%;
3+
text-decoration: none;
4+
margin: 0 auto;
5+
list-style: none;
6+
}
7+
.box-item:hover{
8+
background-color: #e4393c;
9+
color: #fff;
10+
}
11+
.box-item-react:hover{
12+
background-color: #ff2d;
13+
color: #fff;
14+
}

‎src/components/List/index.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import "./index.css";
2+
const List = (props) => {
3+
let list = props?.data ?? [];
4+
console.log(props);
5+
return (
6+
<div>
7+
<ul className="box">
8+
{list.map((v) => {
9+
return (
10+
<li
11+
className={`box-item${v === "React" ? "-react" : ""}`}
12+
key={v}
13+
style={{ height: "50px", lineHeight: "50px" }}
14+
>
15+
{v}
16+
{v === "React" ? <span>1111</span> : null}
17+
</li>
18+
);
19+
})}
20+
</ul>
21+
</div>
22+
);
23+
};
24+
25+
export default List;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /