๐Ÿ”ฅ/์‡ผํ•‘๋ชฐ ๋งŒ๋“ค๊ธฐ

[์‡ผํ•‘๋ชฐ ๋งŒ๋“ค๊ธฐ] React JS - Section 1 / Redux / React Hooks

say! 2022. 7. 21. 15:23
728x90

๐Ÿ“’ ์ฐธ๊ณ  ๊ฐ•์˜

 

[๋ฌด๋ฃŒ] ๋”ฐ๋ผํ•˜๋ฉฐ ๋ฐฐ์šฐ๋Š” ๋…ธ๋“œ, ๋ฆฌ์•กํŠธ ์‹œ๋ฆฌ์ฆˆ - ๊ธฐ๋ณธ ๊ฐ•์˜ - ์ธํ”„๋Ÿฐ | ๊ฐ•์˜

์ด ๊ฐ•์˜๋ฅผ ํ†ตํ•ด์„œ ๋ฆฌ์•กํŠธ์™€ ๋…ธ๋“œ๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ๊ธฐ๋ณธ์ ์ธ ๋‚ด์šฉ๋“ค์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค., - ๊ฐ•์˜ ์†Œ๊ฐœ | ์ธํ”„๋Ÿฐ...

www.inflearn.com


๐ŸŸฃ๋ฐฑ์„œ๋ฒ„์™€ ํ”„๋ก ํŠธ ์„œ๋ฒ„ ๊ฐ™์ด ์ผœ๋Š”๋ฒ•

npm install concurrently --save

index.js ํŒŒ์ผ "scripts"์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๋ฉด npm run dev ํ•˜๋ฉด ๋ฐฑ์„œ๋ฒ„, ํ”„๋ก ํŠธ์„œ๋ฒ„ ๊ฐ™์ด ์ผค ์ˆ˜ ์žˆ์Œ 

"dev": "concurrently \"npm run backend\" \"npm run start --prefix client\""

 

๐ŸŸฃCSS Framework

-CSS Framework ์‚ฌ์šฉ ์ด์œ  : ๊ธฐ๋Šฅ ๋งŒ๋“œ๋Š”๋ฐ ์ง‘์ค‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ

-CSS Framework ์ข…๋ฅ˜ for React JS : Material UI, React Bootstrap, Semantic UI, And Design, Materialize...

! ์ด๋ฒˆ์—๋Š” ant design ์‚ฌ์šฉํ• ๊ฑฐ์ž„ !

 

#ant design

cd client

npm install antd --save

 

 

Ant Design of React - Ant Design

Polyfills are needed for IE browsers. We recommend @babel/preset-env for it. You can set targets config if you are using umi. We recommend using npm or yarn to install, it not only makes development easier, but also allow you to take advantage of the rich

ant.design

 

๐ŸŸฃRedux

state์„ ๊ด€๋ฆฌํ•˜๋Š” ํˆด / Redux is a predictable state container for JavaScript apps. ์ƒํƒœ ๊ด€๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

 

-Props vs State

Props State
1. properties ์ค„์ž„๋ง
2. Props are how components talk to each other
3. Props flow downwards from the parent compnent
4. Props are immutable from the child perspective if you want to change that value? the parent should jst change its internal state
1. parent component์—์„œ child component๋กœ data๋ฅผ ๋ณด๋‚ด๋Š”๊ฒŒ ์•„๋‹Œ ๊ทธ component ์•ˆ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•˜๋ ค๋ฉด? State๋กœ

์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฒ€์ƒ‰ ์ฐฝ์— ๊ธ€์„ ์ž…๋ ฅํ•  ๋•Œ ๊ธ€์ด ๋ณ€ํ•˜๋Š” ๊ฒƒ์€  state๋ฅผ ๋ฐ”๊ฟˆ

2. State is mutable
3.State์ด ๋ณ€ํ•˜๋ฉด re-render๋จ

ํ•œ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ํ๋ฆ„

Action์€ ๊ฐ์ฒด ํ˜•์‹

 

- Redux ์„ค์น˜๋ฒ•

client ํด๋”์—์„œ dependency ๋‹ค์šด๋ฐ›๊ธฐ

npm install redux react-redux redux-promise redux-thunk --save

 

- redux-promise / redux-thunkredux ์—ญํ• 

store ๋ณ€๊ฒฝํ•˜๋Š” ๋ฒ• : dispatch action์œผ๋กœ ๋ณ€๊ฒฝ๊ฐ€๋Šฅ

store์—์„œ ์–ธ์ œ๊ฐ€ ๊ฐ์ฒดํ˜•์‹์œผ๋กœ ๋œ action์„ ๋ฐ›๋Š” ๊ฒƒ์€ ์•„๋‹˜ / promise, functions ํ˜•ํƒœ๋กœ ๋ฐ›์„์ˆ˜๋„ ์žˆ์Œ

> redux store์€ ์˜ค์ง ๊ฐ์ฒด ํ˜•์‹๋งŒ ๋ฐ›์„ ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ redux-thunk๋Š” functions์„ ๋ฐ›๋Š” ๋ฒ•์„ ์•Œ๋ ค์ฃผ๊ณ  redux-promise๋Š” promise ๋ฐ›๋Š” ๋ฒ• ์•Œ๋ ค์ฃผ๋Š” ์—ญํ• ์„ ํ•จ

 

- redux extension ์ถ”๊ฐ€ํ•˜๊ธฐ

 

Redux DevTools

Redux DevTools for debugging application's state changes.

chrome.google.com

 

๐ŸŸฃReact vs React Hooks

-React Component

Class Component Functional Component
Provide more features ๋” ๋งŽ์€ ๊ธฐ๋Šฅ๋“ค Provide less features ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ์ด ํ•œ์ •์ 
Longer Code Shorter Code
More Complex Code Simpler Code
Slower Performance ๋А๋ฆผ Faster Performance ์„ฑ๋Šฅ์ด ๋น„๊ต์  ์ข‹์Œ

 

React Hooks ์ƒ๊น€ > Functional Component with simpler syntax and faster performance ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋จ