From 1b695cb83bf9271747dff579ab90f37b8f0a4d78 Mon Sep 17 00:00:00 2001 From: sunny6312 Date: Sun, 29 Mar 2026 21:15:28 +0900 Subject: [PATCH] Add files via upload --- Accommodate.jsx | 41 +++++++++++++++++++++++++++++++++++++++++ index.js | 44 ++++++++++++++------------------------------ useCounter.jsx | 13 +++++++++++++ 3 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 Accommodate.jsx create mode 100644 useCounter.jsx diff --git a/Accommodate.jsx b/Accommodate.jsx new file mode 100644 index 0000000..be1ff3c --- /dev/null +++ b/Accommodate.jsx @@ -0,0 +1,41 @@ +import React, { useState, useEffect } from "react"; +import useCounter from "./useCounter"; + +const MAX_CAPCITY = 10; + +function Accommodate(props) { + const [isfull, setIsFull] = useState(false); + const [count, increaseCount, decreaseCount] = useCounter(0); + + useEffect(() => { + console.log("=================="); + console.log("useEffect() is called."); + console.log(`isFull: ${isFull}`); + }); + + + useEffect(() => { + setIsFull(count >= MAX_CAPCITY); + console.log(`Current count value: ${count}`); + }, [count]); + + return ( +
+

{`c총 ${count}명 수용했습니다.`}

+ + + + + {isFull &&

정원이 가득찼습니다.

} +
+ ); +} + +export default Accommodate; + + + + + diff --git a/index.js b/index.js index b2e3a49..ea514a2 100644 --- a/index.js +++ b/index.js @@ -1,30 +1,14 @@ -import React from "react"; -import ReactDOM from "react-dom/client"; -import "./index.css"; -import App from "./App"; -import reportWebVitals from "./reportWebVitals";; -import Library from './chapter_03/Library'; -import Clock from './chapter_04/Clock'; -import CommentList from './chapter_05/CommentList'; -import NotificationList from './chapter_06/NotificationList'; -import Accommodate from './chapter_07/Accommodate'; -import ConfirmButton from './chapter_08/ConfirmButton'; -import LandingPage from './chapter_09/LandingPage'; -import AttendanceBook from './chapter_10/AttendanceBook'; -import SignUp from './chapter_11/SignUp'; -import Calculator from './chapter_12/Calculator'; -import ProfileCard from './chapter_13/ProfileCard'; -import DarkOrLight from './chapter_14/DarkOrLight'; -import Blocks from './chapter_15/Blocks'; - -ReactDOM.render( - - - , - document.getElementById('root') -); - -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); \ No newline at end of file +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +import Accommodate from './chapter_07/Accommodate'; + +ReactDOM.render( + + + , + document.getElementById('root') +); \ No newline at end of file diff --git a/useCounter.jsx b/useCounter.jsx new file mode 100644 index 0000000..b1553c1 --- /dev/null +++ b/useCounter.jsx @@ -0,0 +1,13 @@ +import React, { useState } from "react"; + +function useCounter(initialValue) { + const [count, setCount] = useState(initialValue) ; + + const increaseCount = () => setCount((count) => count + 1); + const decreaseCount = () => setCount((count) => Math.max(count -1, 0)); + + return [count, increaseCount, decreaseCount]; + +} + +export default useCounter; \ No newline at end of file