Skip to content

Commit

Permalink
App.tsx, main.tsx 파일 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
u-ryu-00 committed Aug 16, 2023
1 parent 4bfeb1d commit 97cc079
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</head>
<body>
<div id="root"></div>
<div id="demo"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"parcel": "^2.9.3",
"process": "^0.11.10",
"typescript": "^5.1.6"
},
"dependencies": {
Expand Down
19 changes: 19 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {useState} from 'react';

export default function App() {
const [count, setCount] = useState(0);

const handleClick = () => {
setCount(count + 1);
};

return (
<div>
<p>Hello, world!</p>
<p>Count: {count}</p>
<button type='button' onClick={handleClick}>
클릭!
</button>
</div>
);
}
33 changes: 30 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,35 @@ import ReactDOM from 'react-dom/client';

import App from './App';

const container = document.getElementById('app');
function Demo({count}: {
count: number;
}) {
return (
<p>DEMO: {count}</p>
);
}

const root = ReactDOM.createRoot(container);
function main() {
const element = document.getElementById('root');
const element2 = document.getElementById('demo');

root.render(<App />);
if (!element || !element2) {
return;
}

const root = ReactDOM.createRoot(element);
const root2 = ReactDOM.createRoot(element2);

root.render(<App />);

let count = 0;

root2.render(<Demo count={count}/>);

setInterval(() => {
count += 1;
root2.render(<Demo count={count}/>);
}, 1_000);
}

main();

0 comments on commit 97cc079

Please sign in to comment.