๐ JavaScript์ Modern Features์ React ๊ธฐ์ด
1. Optional Chaining๊ณผ Null ๋ณํฉ ์ฐ์ฐ์
Optional Chaining (?.)
- ๊ฐ์ฒด์ ์์ฑ์ ์์ ํ๊ฒ ์ ๊ทผ
- undefined ๋ฐํ (์๋ฌ ๋ฐฉ์ง)
Null ๋ณํฉ ์ฐ์ฐ์ (??)
||(๋
ผ๋ฆฌํฉ ์ฐ์ฐ์)์์ ์ฐจ์ด์ : 0, '' ์ ๊ฐ์ falsy ๊ฐ์ ์ ํจํ ๊ฐ์ผ๋ก ์ฒ๋ฆฌ
const temperature = 0;
console.log(temperature ?? 25);
console.log(temperature || 25);
2. Framework vs Library
Framework
- ์์ ํ ํ๋ก๊ทธ๋๋ฐ ์ธํ๋ผ ์ ๊ณต
- ์: Spring, Vue.js, Angular.js
- ์ ์ด์ ์ญ์ (IoC) ํน์ง
Library
- ํน์ ๊ธฐ๋ฅ์ ๋ชจ๋ํ๋ ์งํฉ
- ์: React.js, react-router-dom
- ๊ฐ๋ฐ์๊ฐ ์ ์ด ํ๋ฆ ๊ด๋ฆฌ
3. React ๋ผ์ฐํ
Hash Routing vs Browser Routing
Hash: www.sample-homepage.com/#about
Browser: www.sample-homepage.com/about
- Browser Routing์ด ๋ ๊น๋ํ URL ์ ๊ณต
- SPA ํน์ฑ ์ ์ง (๋จ์ผ HTML)
4. React ํ๋ก์ ํธ ์์ฑ ๋๊ตฌ
CRA vs Vite
yarn create-react-app xxxx
yarn create vite xxxx --template react
Vite์ ์ฅ์ :
- ๋น ๋ฅธ ๋น๋ ์๋ (Esbuild ์ฌ์ฉ)
- ์ ์ฐํ ์ค์
- ๋ค์ํ ํ๋ ์์ํฌ ์ง์
5. ๋ถ๋ณ์ฑ๊ณผ DOM ์กฐ์
๋ฐ์ดํฐ ๋ถ๋ณ์ฑ
- ์์ ๋ฐ์ดํฐ: ์๋ก์ด ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ ํ ๋น
- ๊ฐ์ฒด: ๊ธฐ์กด ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ ๊ฐ ๋ณ๊ฒฝ
Virtual DOM ์ฒ๋ฆฌ ๊ณผ์
- ๋ ๊ฐ์ง ๋ฒ์ ์ ๊ฐ์ DOM ์ ์ง
- Diffing: ๋ณ๊ฒฝ์ฌํญ ํ์
- Reconciliation: Batch Update๋ก ์ค์ DOM ์ ์ฉ
๐ก ์ค๋์ ๋ฐฐ์
- JavaScript์ ์ต์ ๋ฌธ๋ฒ์ด ์ค์ ๋ก ์ด๋ค ์ํฉ์์ ์ ์ฉํ์ง ์ดํด
- React์ ๊ธฐ๋ณธ ๊ฐ๋
๊ณผ ์๋ ๋ฐฉ์์ ๋ํ ์ดํด ํฅ์
- ํ๋ก ํธ์๋ ๊ฐ๋ฐ ๋๊ตฌ๋ค์ ํน์ฑ๊ณผ ์ฅ๋จ์ ํ์
๐ ์ค๋ฌด ์ ์ฉ ํฌ์ธํธ
- Null ๋ณํฉ ์ฐ์ฐ์๋ฅผ ํ์ฉํ ์์ ํ ๊ธฐ๋ณธ๊ฐ ์ฒ๋ฆฌ
- Browser Routing์ ํตํ ๊น๋ํ URL ๊ตฌ์กฐ ์ค๊ณ
- Vite์ ์ฅ์ ์ ํ์ฉํ ๊ฐ๋ฐ ํ๊ฒฝ ์ต์ ํ
- ๋ถ๋ณ์ฑ์ ๊ณ ๋ คํ ์ํ ๊ด๋ฆฌ ๊ตฌํ