Skip to content

Commit 8a79585

Browse files
committed
2주차 퀴즈 카운터 추가
1 parent 69e899b commit 8a79585

File tree

7 files changed

+58
-6
lines changed

7 files changed

+58
-6
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export default [
3030
...reactHooks.configs.recommended.rules,
3131
"react/prop-types": "off",
3232
"react/jsx-no-target-blank": "off",
33+
"react/rule-of-hook": "off",
34+
"react-hooks/rules-of-hooks": "off",
3335
"react-refresh/only-export-components": [
3436
"warn",
3537
{ allowConstantExport: true },

src/App.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Button from "./components/Button";
2+
import Counter from "./components/Counter";
23
import Input from "./components/Input";
34
import Wrapper from "./components/Wrapper";
45

@@ -7,6 +8,8 @@ function App() {
78
<Wrapper>
89
<Input />
910
<Button />
11+
<h3>카운터</h3>
12+
<Counter />
1013
</Wrapper>
1114
);
1215
}

src/components/Button.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { StyledButton } from "./styles";
22

33
function Button() {
4-
return <StyledButton onClick={alert("제출 버튼 클릭")}>제출</StyledButton>;
4+
return <StyledButton onClick={()=>alert("제출 버튼 클릭")}>제출</StyledButton>;
55
}
66

77
export default Button;

src/components/Counter.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useState } from "react";
2+
import { StyledButton, ConterWrapper } from "./styles";
3+
4+
function Counter() {
5+
const [isSent, setIsSent] = useState(false);
6+
7+
if (isSent) {
8+
return <div> 전송되었습니다.</div>;
9+
} else {
10+
const [count, setCount] = useState(0);
11+
return (
12+
<ConterWrapper>
13+
{count}
14+
<ButtonWrapper>
15+
<StyledButton onClick={() => setCount(count + 1)}>
16+
더하기
17+
</StyledButton>
18+
<StyledButton onClick={() => setIsSent(true)}>Send</StyledButton>
19+
</ButtonWrapper>
20+
</ConterWrapper>
21+
);
22+
}
23+
}
24+
25+
export default Counter;

src/components/Input.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { StyledInput } from "./styles";
22

33
function Input() {
4-
return <StyledInput />;
4+
return (
5+
<>
6+
<h3> 입력</h3>
7+
<StyledInput />
8+
</>
9+
);
510
}
611

712
export default Input;

src/components/Wrapper.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { StyledWrapper } from "./styles";
2-
function Wrapper() {
2+
function Wrapper({ children }) {
33
const clickFunc = () => {
44
alert("배경 클릭");
55
};
66
return (
7-
<StyledWrapper onClick={clickFunc()}>배경을 클릭할 수 있어요</StyledWrapper>
7+
<StyledWrapper onClick={clickFunc()}>
8+
<h2>배경을 클릭할 수 있어요</h2>
9+
{children}
10+
</StyledWrapper>
811
);
912
}
1013

src/components/styles.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import styled from "styled-components";
22

33
export const StyledWrapper = styled.form`
44
width: 100%;
5-
height: 300px;
65
background-color: skyblue;
76
display: flex;
87
align-items: center;
@@ -18,7 +17,6 @@ export const StyledInput = styled.input`
1817
border: none;
1918
border-radius: 15px;
2019
font-size: 20px;
21-
margin-top: 20px;
2220
z-index: 10;
2321
&:focus {
2422
outline: none;
@@ -35,3 +33,19 @@ export const StyledButton = styled.button`
3533
font-size: 20px;
3634
margin-top: 20px;
3735
`;
36+
37+
export const ConterWrapper = styled.div`
38+
width: 100%;
39+
display: flex;
40+
justify-content: center;
41+
align-items: center;
42+
flex-direction: column;
43+
`;
44+
45+
export const ButtonWrapper = styled.div`
46+
display: flex;
47+
justify-content: center;
48+
align-items: center;
49+
flex-direction: row;
50+
gap: 10px;
51+
`;

0 commit comments

Comments
 (0)