๐ฝ์์ ๋ง๋งํ ๋์ ์ฝ๋
const todoTitle = document.getElementsByClassName('todo_title')
console.log(todoTitle);
todoTitle.style.backgroundColor = 'red'
๋ธ!๊น๐ฑ๐ฒ
๋ฐ๋ณด! HTMLCollection
์ ์ ์ฌ๋ฐฐ์ด์ด๋ผ๊ณ ^^
์ ์ฌ๋ฐฐ์ด์ Array์ ๋ด์ฅํจ์๋ฅผ ์ธ ์ ์๋ต๋๋ค์!
Array.from
์ผ๋ก ๋ฐฐ์ด์ฒ๋ผ ํด์ฃผ๊ณforEach
์จ์ ํ๋์ฉ ๋ฐ๊ฟ์ฃผ์ธ์ฌ
const todoTitle = Array.from(document.getElementsByClassName('todo_title'))
console.log(todoTitle); // ๐ [h3.todo_title, h3.todo_title, h3.todo_title]
todoTitle.forEach(todoTitle => {
todoTitle.style.color = "red"
})
๋ฆฌ์กํธ ์๋ฆฌ๋จผํธ๋ฅผ ์ปดํฌ๋ํธ๋ก ๋ง๋ค์ด์ ํ์ฉ
// index.js
import ReactDOM from 'react-dom'
function Hello() {
return <h1>๋ฆฌ์กํธ์ผ ์ด๋ ค์กฐ</h1>;
}
const element = {
<>
<Hello /> // ๐ Helloํจ์๊ฐ ๋ฆฌํดํ๋ ๋ฆฌ์กํธ ์๋ฆฌ๋จผํธ
<Hello />
<Hello />
</>
);
ReactDom.render(element, document.geElementById('root'));
element ๋ณ์์์ JSX์ฝ๋๋ฅผ ์์ฑํ ๋ ํจ์์ด๋ฆ(Hello
)์ ๊ฐ์ง ํ๊ทธ๋ฅผ ์ฌ์ฉํ ์ ์๋ค...์ด๊ฒ ๋ฐ๋ก ๋ฆฌ์กํธ ์ปดํฌ๋ํธ(React Component)
index.js
|App.js
|index.html
๋ฉ์ธ ํ๋ก๊ทธ๋จ! ์ฌ๊ธฐ์ HTMLํ ํ๋ฆฟ & ์๋ฐ์คํฌ๋ฆฝํธ ์ปดํฌ๋ํธ๋ฅผ ์กฐํฉํด์ ๋ ๋๋งํ๊ณ ๋ทฐ์ ๋ณด์ฌ์ค [ HTML Template + Component =(rendering)=>> View ]
์ปดํฌ๋ํธ ์ ์ํ๋ ํ๋ก๊ทธ๋จ!!! ์ค์ ๋ก ํ๋ฉด์ ํ์๋๋ ๋ด์ฉ๋ค์ ์ฌ๊ธฐ์ ๋ง๋ค์ด์ง๋น!
index.js์ ๋์ ๋๋ค. HTMLํ
ํ๋ฆฟ ํ์ผ์!!
<์ง์ ํ์๋๋๊ฑด ์๋๊ณ index.js์ ์ํด ์ผ์ด๋ ๋ ๋๋ง ๊ฒฐ๊ณผ๊ฐ ํ์๋์ด์!>
โ ๏ธ ์ด๋ฆ ๋ฐ๊พธ์ง๋ง์์ค!
๐ฝ react์์ ์ ๊ณตํ๋ ์ปดํฌ๋ํธ ํด๋์ค๋ฅผ ์์๋ฐ์์ ๊ตฌํํ๊ธฐ ์ํด์ {Component}๋ฅผ ์ํฌํธ!!!!
import React, {Component} from 'react';
๐ฝ ํจ์ํ ์ปดํฌ๋ํธ
function UserGreeting(props) {
return <h1>Welcome back!</h1>;
}
function GuestGreeting(props) {
return <h1>Please sign up.</h1>;
}
function Greeting(props) {
const isLoggedIn = props.isLoggedIn;
if (isLoggedIn) {
return <UserGreeting />;
}
return <GuestGreeting />;
}
๐ฝ ๋ ๋๋ง...
ReactDOM.render(
// Try changing to isLoggedIn={true}:
<Greeting isLoggedIn={false} />,
document.getElementById('root')
);
์ธ๋ค์ผ์ด ์ฐฐ์ง๋ค์