<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<h2>안녕하세요</h2>
<div id="root"></div>
<h3>root1</h3>
<div id="root1"></div>
<h3>root2</h3>
<div id="root2"></div>
<h3>root3</h3>
<div id="root3"></div>
<script src="react.develpment.js"></script>
<script src="react-dom.development.js"></script>
<script src="simple1.js"></script>
</body>
</html>
function LikeButton(){
// likebutton에 liked라는 상태값을 추가
const [liked, setLiked] = React.useState(false);
const text = liked ? '좋아요 취소' : '좋아요';
return React.createElement(
'button',
{ onClick: () => setLiked(!liked)},
text,
)
}
// const domContainer = document.getElementById('root');
// ReactDOM.render(React.createElement(LikeButton), domContainer);
const domContainer = document.getElementById('root');
ReactDOM.render(
React.createElement(
'div',
null,
React.createElement(LikeButton),
React.createElement(LikeButton),
React.createElement(LikeButton),
),
domContainer
);
const domContainer1 = document.getElementById('root1');
ReactDOM.render(React.createElement(LikeButton), domContainer1);
const domContainer2 = document.getElementById('root2');
ReactDOM.render(React.createElement(LikeButton), domContainer2);
const domContainer3 = document.getElementById('root3');
ReactDOM.render(React.createElement(LikeButton), domContainer3);
// React.createElement(
// 'div',
// null,
// React.createElement('p',null,'hello'),
// React.createElement('p',null,'world'),
// );
'front-end > react' 카테고리의 다른 글
[리액트] create-react-app (0) | 2021.03.15 |
---|---|
[리액트] 웹팩 webpack (0) | 2021.03.15 |
[리액트] 바벨 babel (0) | 2021.03.14 |
[리액트] Target container is not a DOM element. 에러 (0) | 2021.03.14 |
[리액트] 컴포넌트 - 프로퍼티 / 상태관리 (setState / forceUpdate) (0) | 2021.03.12 |
[리액트] 개발환경 설치하기 (0) | 2021.03.12 |
[리액트] 기본 (0) | 2021.03.12 |