Skip to content

Latest commit

ย 

History

History
46 lines (38 loc) ยท 3.89 KB

thinking.md

File metadata and controls

46 lines (38 loc) ยท 3.89 KB
  • React์—์„œ ์ƒํƒœ๊ด€๋ฆฌ๋Š” ์™œ ํ•„์š”ํ•œ๊ฐ€? => ๊ฐ ์ปดํฌ๋„ŒํŠธ์˜ props๋Š” ์„œ๋กœ๊ฐ€ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„์ผ ๋•Œ ์ „๋‹ฌํ•˜๊ณ , ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ๋‘ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์„œ๋กœ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด, props๋ฅผ ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด์„œ ํฐ ๋…ธ๋ ฅ๊ณผ ์‹œ๊ฐ„์ด,,๋“ ๋‹ค (props drilling) ๊ฐ ์ปดํฌ๋„ŒํŠธ ๊ฐ„ ๋ฐ์ดํ„ฐ ์—ฐ๊ฒฐ์ด ๋งŽ์•„์ง€๊ฒŒ ๋˜๋ฉด ์–ด๋–ค ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์–ด๋–ค props๋ฅผ ์–ด๋””๋กœ ์–ด๋–ป๊ฒŒ ๋„˜๊ฒจ์ฃผ๊ณ  ์žˆ๋Š”์ง€์— ๊ด€ํ•ด ์ถ”์ ํ•˜๊ธฐ์— ๋งค์šฐ ํž˜์ด ๋“ค ๊ฒƒ์ด๋‹ค. ๋”ฐ๋ผ์„œ, React์—์„œ ์ƒํƒœ ๊ด€๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๊ฒŒ ๋œ๋‹ค.

=> state๋Š” ๋ฆฌ์•กํŠธ ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์—์„œ ๋ฐ”๋€Œ๋Š” ๊ฐ’์ด๋‹ค. ์ด๋•Œ state(์ƒํƒœ)๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด, ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง๋˜๊ณ  ์ด๋•Œ ์ž์‹ ์ปดํฌ๋„ŒํŠธ์—๊ฒŒ ์ด state๋ฅผ props๋กœ ๋ฌผ๋ ค์ฃผ๊ฒŒ ๋œ๋‹ค. ํ•˜์ง€๋งŒ, ํ”„๋กœ์ ํŠธ๊ฐ€ ๋ณต์žกํ•ด์ง€๊ณ  ๊ณต์œ ํ•ด์•ผ ํ•˜๋Š” state๊ฐ€ ์ฆ๊ฐ€ํ•  ์ˆ˜๋ก ๋งค๋ฒˆ ์ „๋‹ฌ ๊ณผ์ •์„ ๊ฑฐ์ณ์•ผ ํ•˜๋Š” ์ƒํ™ฉ์— ์ง๋ฉดํ•˜๊ฒŒ ๋œ๋‹ค. ๋”ฐ๋ผ์„œ, state ๊ฐ’์ด ์–ด๋””์—์„œ ๋ณ€ํ•˜๋Š” ์ง€, ์ดํ›„ ์ด ์ž‘์—…์œผ๋กœ ์ธํ•ด ์–ด๋–ค ์—…๋ฐ์ดํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š” ์ง€ ์•Œ์•„๋‚ด๊ธฐ ํž˜๋“ค๋‹ค

  • ๊ด€๋ฆฌ ํ•ด์•ผ ํ•˜๋Š” ์ƒํƒœ์— ๋Œ€ํ•œ ๊ธฐ์ค€์€ ๋ฌด์—‡์ธ๊ฐ€? => ์ƒํƒœ์˜ ์ข…๋ฅ˜ ->๋กœ์ปฌ ์ƒํƒœ: ํŠน์ • ์ปดํฌ๋„ŒํŠธ ์•ˆ์—์„œ๋งŒ ๊ด€๋ฆฌ ->์ง€์—ญ ์ƒํƒœ: state๊ฐ€ ๋ช‡๋ช‡์— ๊ตญํ•œ๋˜์–ด ์˜ํ–ฅ ->์ „์—ญ ์ƒํƒœ: ์ „์ฒด ํ˜น์€ ์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋™์‹œ์— ๊ฑธ์ณ ๊ด€๋ฆฌ๋˜๋Š” ๊ฒฝ์šฐ ๋Œ€์ฒด๋กœ ์ „์—ญ ์ƒํƒœ๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•œ๋‹ค (ex, ํ…Œ๋งˆ ์„ค์ •, ์–ธ์–ด ์„ค์ • ๋“ฑ, ์™ธ์—๋„ props๋ฅผ ๋™์‹œ์— ๊ฐ–๋Š” ์—ฌ๋Ÿฌ ๊ฒฝ์šฐ๋“ค) ์ „์—ญ ์ƒํƒœ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ: ์ „์—ญ์ƒํƒœ๊ฐ€ ๋ฐ”๋€” ๋•Œ๋งˆ๋‹ค ๋ฆฌ๋ Œ๋”๊ฐ€ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ์Œ, ๋ณ€ํ™”๊ฐ€ ์žฆ์ง€ ์•Š๊ณ  ์„œ๋น„์Šค ์ „๋ฐ˜์— ๊ฑธ์นœ ๊ฒฝ์šฐ ์ „์—ญ ์ƒํƒœ ์ด์šฉ

  • ์–ด๋–ค ์ƒํƒœ๊ด€๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์–ด๋–ค ์ƒํ™ฉ์—์„œ ์‚ฌ์šฉํ•ด์•ผ ํ• ๊นŒ? ( ์žฅ๋‹จ์  ๋˜๋Š” ๊ฐ„๋‹จ ๋น„๊ต ๋ถ„์„ ) =>Redux: ์ƒํƒœ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ JS ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, Flux ์•„ํ‚คํ…์ณ๋ฅผ ๋”ฐ๋ฅด๋ฉฐ ๋‹จ๋ฐ˜ํ–ฅ ๋ฐ์ดํ„ฐ ํ๋ฆ„ ๋ชจ๋ธ์„ ํ†ตํ•ด ์ƒํƒœ ๊ด€๋ฆฌ, ํ™•์žฅ์„ฑ์„ ๋Š˜๋ ค์คŒ ์žฅ์ : ์ƒํƒœ ์˜ˆ์ธก ๊ฐ€๋Šฅ, ์œ ์ง€ ๋ณด์ˆ˜ ์šฉ์ด, ๋””๋ฒ„๊น…์ด ์‰ฌ์›€, ํ•œ ๊ณณ์—์„œ ๊ด€๋ฆฌ ๋‹จ์ : ์ฝ”๋“œ์˜ ์ค‘๋Ÿ‰, ์ฝ๊ธฐ ์ „์šฉ์œผ๋กœ ๋งŒ๋“ค์–ด ์ฃผ์ง€ ์•Š์Œ, ์—ฐ๊ฒฐ์„ฑ(mapStateToProps์™€ ๊ฐ™์€ ๋ฉ”์„œ๋“œ ํ•„์š”)

=> MobX: functional reactive programming์„ ํˆฌ๋ช…ํ•˜๊ฒŒ ์ ์šฉ ์žฅ์ : ๊ฐ์ฒด ์ง€ํ–ฅ์ , ๊น”๋”ํ•˜๊ฒŒ ๊ตฌ์„ฑ, ์บก์Šํ™”(๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด์„œ๋งŒ state ๋ณ€๊ฒฝ) ๋‹จ์ : ๋ถˆํŽธํ•œ ๋””๋ฒ„๊น…(console.log์ด์šฉ), ํ•จ์ˆ˜ํ˜• ๊ตฌ์„ฑ์ด๋ผ๋ฉด ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด useContext๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ, ์—ฐ๊ฒฐ์„ ์œ„ํ•ด hoc๋กœ ๋žฉํ•‘ํ•ด์•ผ ํ•จ, ๋ ˆํผ๋Ÿฐ์Šค ๋ถ€์กฑ

=> Context API: ์žฅ์ : ์ ‘๊ทผ์„ฑ์ด ๋‚ฎ์Œ, ๋Ÿฌ๋‹ ์ปค๋ธŒ๊ฐ€ ๋‚ฎ๊ณ  ๊ฐ„๊ฒฐํ•จ ๋‹จ์ : rendering(value๊ฐ’์ด ๋ณ€ํ•  ๊ฒฝ์šฐ ์ปดํฌ๋„ŒํŠธ ๋˜ํ•œ ๋ฆฌ๋žœ๋”๋ง) ๊ด€์‹ฌ์‚ฌ์— ๋”ฐ๋ผ ๋ชจ๋‘ ๋ถ„๋ฆฌํ•ด์„œ ๊ด€๋ฆฌํ•ด์•ผ ํ•จ

=>Recoil: meta์—์„œ ๋งŒ๋“  ์ƒํƒœ๊ด€๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ธฐ์กด context์˜ ๋ฌธ์ œ, ์ฝ”๋“œ ๋ถ„ํ™œ์˜ ์–ด๋ ค์›€์„ ํ•ด๊ฒฐํ•˜๊ณ ์ž ๋งŒ๋“ฆ ์žฅ์ : ๊ฐ„๋‹จํ•œ ์ธํ„ฐํŽ˜์ด์Šค, ์ฆ๋ถ„ ๋ฐ ๋ถ„์‚ฐ, ์ปดํฌ๋„ŒํŠธ ๋น„์ˆ˜์ • ๋‹จ์ : ๋ ˆํผ๋Ÿฐ์Šค ๋ถ€์กฑ, ํ˜ธํ™˜์„ฑ

  • React์—์„œ ๋ Œ๋”๋ง์„ ํšจ๊ณผ์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ด ์žˆ์„๊นŒ? => state ์„ ์–ธ ์œ„์น˜(์ปดํฌ๋„ŒํŠธ ์ตœ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ) => ๊ฐ์ฒด ํƒ€์ž…์˜ state๋Š” ์ตœ๋Œ€ํ•œ ๋ถ„ํ• ํ•˜๊ธฐ => hooks์—์„œ shouldComponentUpdate ๋Œ€์ฒด(React.memo) => React.memo => mapํ•จ์ˆ˜ ์‚ฌ์šฉ์‹œ index๋กœ key๊ฐ’ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ => useMemo: ์ข…์† ๋ณ€์ˆ˜๋“ค์ด ๋ณ€ํ•˜์ง€ ์•Š์œผ๋ฉด ํ•จ์ˆ˜๋ฅผ ๊ตณ์ด ๋‹ค์‹œ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋„๋ก ํ•˜์—ฌ ์‹œ๊ฐ„๊ณผ ๋ฆฌ๋ Œ๋”๋ง ๋ฐฉ์ง€ =>useCallback : ์ข…์† ๋ณ€์ˆ˜๋“ค์ด ๋ณ€ํ•˜์ง€ ์•Š์œผ๋ฉด ๊ตณ์ด ํ•จ์ˆ˜๋ฅผ ์žฌ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์— props๋กœ ์ „๋‹ฌํ•˜๊ธฐ

  • ์ด๋ฅผ ์œ„ํ•ด ์–ด๋–ค ์‹์œผ๋กœ ๋น„์ฆˆ๋‹ˆ์Šค ์„ค๊ณ„๋ฅผ ์ง„ํ–‰ํ•ด์•ผ ํ• ๊นŒ => ์ปดํฌ๋„ŒํŠธ ๊ตฌ์กฐ๋ฅผ ๋ช…ํ™•ํ•˜๊ณ  ์ง๊ด€์ ์ด๊ณ  ์ตœ์†Œํ™”ํ•˜๊ธฐ! ๋˜ํ•œ state์˜ ์ ์ ˆํ•œ ์„ค๊ณ„!! ์ปดํฌ๋„ŒํŠธ๋ฅผ ์žฌ์‚ฌ์šฉ์„ฑ๊ณผ ๋ฒ”์šฉ์„ฑ์— ๋งž์ถ”์–ด์„œ ์„ค๊ณ„