๐ ์ฐธ๊ณ ๊ฐ์
[๋ฌด๋ฃ] ๋ฐ๋ผํ๋ฉฐ ๋ฐฐ์ฐ๋ ๋ ธ๋, ๋ฆฌ์กํธ ์๋ฆฌ์ฆ - ๊ธฐ๋ณธ ๊ฐ์ - ์ธํ๋ฐ | ๊ฐ์
์ด ๊ฐ์๋ฅผ ํตํด์ ๋ฆฌ์กํธ์ ๋ ธ๋๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ๊ธฐ๋ณธ์ ์ธ ๋ด์ฉ๋ค์ ๋ฐฐ์ธ ์ ์์ต๋๋ค., - ๊ฐ์ ์๊ฐ | ์ธํ๋ฐ...
www.inflearn.com
โ React JS๋?
- Library, Made by Facebook, Released in 2013
- Components module๊ณผ ๋น์ทํ๊ฒ ์ปดํฌ๋ํธ๋ก ์ด๋ค์ ธ ์์ด์ reusable ๋ฐ์ด๋จ
- Virtual DOM
# Real DOM vs Virtual DOM
Real DOM : ๋ง์ฝ 10๊ฐ์ ๋ฆฌ์คํธ๊ฐ ์์ ๋ ๊ทธ ์ค์ ํ๊ฐ์ง์ ๋ฆฌ์คํธ๋ง Update ๋จ > ์ ์ฒด ๋ฆฌ์คํธ๋ฅผ ๋ค์ Reload ํด์ผ๋จ, Super Expensiveํ ์์
Virtual DOM : ๋ง์ฝ 10๊ฐ์ ๋ฆฌ์คํธ๊ฐ ์์ ๋ ๊ทธ ์ค์ ํ๊ฐ์ง์ ๋ฆฌ์คํธ๋ง Update ๋จ > ๊ทธ ๋ฐ๋ ํ ๊ฐ์ง ์์ดํ ๋ง DOM์์ ๋ฐ๊ฟ์ค
# Babel
์ต์ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ์ ์ง์ํ์ง ์๋ ๋ธ๋ผ์ฐ์ ๋ฅผ ์ํด์ ์ต์ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ์ ๊ตฌํ ๋ธ๋ผ์ฐ์ ์์๋ ๋ ์ ์๊ฒ ๋ณํ ์์ผ์ค(ES5 ๋ฌธ๋ฒ์ผ๋ก ๋ณํ)
# Webpack
๋ง์ ๋ชจ๋๋ค์ ๊ฐ๋จํ๊ฒ ๋ง๋ค์ด์ค
# ๋ค์ด๋ก๋
client ํด๋์์ npx create-react-app .
# npm & npx
NPM (Node Package Manager) : online repository for the publishing of open-source Node.js projects ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ๋ด๊ณ ์๋ ์ ์ฅ์ ์ญํ , command-line utility for interacting with the said repository that aids in package installation, version management, and dependency management ํ์ผ ๋น๋์ํฌ ๋ ์ฌ์ฉ, package.js์์ ํ์ธ๊ฐ๋ฅ
> ์๋๋ create-react-app์ ํ ๋ npm install -g create-react-app ์ด๋ ๊ฒ ํด์ global ๋๋ ํ ๋ฆฌ์ ๋ค์ด๋ฐ์์
> ์ด์ ๋ npx ์ด์ฉํด์ ๊ทธ๋ฅ create-react-app ์ด์ฉํ ์ ์์ (npx๊ฐ npm registry์์ create-react-app์ ์ฐพ์์ ๋ค์ด๋ก๋ ์์ด ์คํ์์ผ์ค)
> Disk space ๋ญ๋นํ์ง ์์ ์ ์์, ํญ์ ์ต์ ๋ฒ์ ์ฌ์ฉ๊ฐ๋ฅ
npm run start
LandingPages : ์ฒ์ ํ์ด์ง
hoc : ๋ค๋ฅธ ์ปดํฌ๋ํธ๋ฅผ ๊ฐ์ง๋ function
๐ฃํ์ด์ง ์ด๋
App.js
ํ์ด์ง ์ด๋์ ํ ๋ React Router Dom ์ ์ฌ์ฉ
React Router | Quick Start
Declarative routing for React apps at any scale
reactrouter.com
#Dependency ๋ค์ด๋ก๋
npm install react-router-dom --save
#Data Request, Response Flow ๊ทธ๋ฆฌ๊ณ Axios
๐ฃCORS ์ด์
๋ค๋ฅธ ํฌํธ๋ฅผ ๊ฐ์ง๊ณ ์๋ ์๋ฒ๋ ์๋ฌด ์ค์ ์์ด Request๋ฅผ ๋ณด๋ผ ์ X
> Cors ์ ์ฑ ๋๋ฌธ > Cross-Origin Resource Sharing (CORS) ๋ณด์์ ์ํด์
๐ฃProxy
Proxy๋ฅผ ์ฌ์ฉํด์ CORS ์ด์ ํด๊ฒฐํ๊ธฐ
๋ค์ด๋ก๋
$ npm install http-proxy-middleware --save
Proxying API Requests in Development | Create React App
Note: this feature is available with react-scripts@0.2.3 and higher.
create-react-app.dev
์ ์ฌ์ดํธ Configuring the Proxy Manually ๋ถ๋ถ ์ฐธ์กฐ
src ํด๋์ setupProxy.js ํ์ผ ๋ง๋ค๊ณ ์๋ ์ฝ๋ ๋ถ์ฌ๋ฃ๊ธฐ
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true,
})
);
};
> CORS ์ด์ ํด๊ฒฐ!
#Proxy Server ์ญํ
#Proxy server ์ฌ์ฉ ์ด์
-ํ์ฌ์์ ์ง์๋ค์ด๋ ์ง์์์ ์์ด๋ค ์ธํฐ๋ท ์ฌ์ฉ ์ ์ด
-์บ์ฌ๋ฅผ ์ด์ฉํด ๋ ๋น ๋ฅธ ์ธํฐ๋ท ์ด์ฉ ์ ๊ณต
-๋ ๋์ ๋ณด์ ์ ๊ณต
-์ด์ฉ ์ ํ๋ ์ฌ์ดํธ ์ ๊ทผ ๊ฐ๋ฅ