실제 실습 내용
- create-react로 만든 my-app 프로젝트를 열어 chapter_04 폴더 생성
- Clock.jsx 코드 작성
import React from "react";
function Clock(props){
return (
<div>
<h1>안녕, 리액트!</h1>
<h2>현재 시간 : {new Date().toLocaleTimeString()}</h2>
</div>
);
}
export default Clock;
- index.js 코드 변경
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';
setInterval(() => {
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<Clock />
</React.StrictMode>,
document.getElementById('root')
);
}, 1000);
// 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();
실행 결과
'React > 처음 만난 리액트(react)' 카테고리의 다른 글
State와 Lifecycle의 정의 (0) | 2023.10.11 |
---|---|
(실습) 댓글 컴포넌트 만들기 (0) | 2023.09.29 |
Component 합성과 추출 (0) | 2023.09.29 |
Component 만들기 및 렌더링 (0) | 2023.09.29 |
Props의 특징 및 사용법 (0) | 2023.09.29 |