Skip to content

Add translation of hooks-effect - #205

Merged
hg-pyun merged 7 commits into
reactjs:masterfrom
yumidev:hooks_effect
Mar 6, 2020
Merged

hg-pyun merged 7 commits into
reactjs:masterfrom
yumidev:hooks_effect

Conversation

@yumidev

@yumidev yumidev commented Jan 29, 2020 •

Copy link
Copy Markdown
Contributor

@netlify

netlify Bot commented Jan 29, 2020 •

Copy link
Copy Markdown

Deploy preview for ko-reactjs-org ready!

Built with commit 6330b28

https://deploy-preview-205--ko-reactjs-org.netlify.com

@yumidev
yumidev force-pushed the hooks_effect branch 9 times, most recently from fbf65d4 to 811ea75 Compare January 29, 2020 15:41

@anthonyminyungi anthonyminyungi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yumidev ๋‹˜ ์•ˆ๋…•ํ•˜์„ธ์š”.
๋ฆฌ๋ทฐ ์š”์ฒญํ•˜์„œ์„œ ํ•œ๋ฒˆ ์ญ‰ ์ฝ์–ด๋ณด๊ณ  ๊ฐœ์ธ์ ์ธ ๊ฐ์ƒ์„ ๋‚จ๊ฒจ๋ณด์•˜์Šต๋‹ˆ๋‹ค.
์šฐ์„  ์ „์ฒด์ ์œผ๋กœ ์งœ์ž„์ƒˆ ์žˆ๊ฒŒ ์ž˜ ๋ฒˆ์—ญ์ด ๋˜์–ด ์žˆ์–ด์„œ ๊ต‰์žฅํžˆ ์ข‹๊ฒŒ ์ฝ์—ˆ์Šต๋‹ˆ๋‹ค.
๋‹ค๋งŒ ๋ช‡ ๊ฐ€์ง€ ์ฒจ์–ธ๋“œ๋ฆฌ๊ณ  ์‹ถ์€ ๊ฒƒ์ด ์žˆ์–ด์„œ ๋ช‡ ์ž ์ ์–ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

์ €์˜ ๋ฆฌ๋ทฐ๋Š” ์ฐธ๊ณ  ์‚ฌํ•ญ์œผ๋กœ๋งŒ ๋ณด์‹œ๊ณ  ํ•œ ํŽธ์œผ๋กœ ํ˜๋ฆฌ์‹  ๋’ค์—
๋ฉ”์ธํ…Œ์ด๋„ˆ ๋ถ„๋“ค๊ณผ ๊ด€๋ฆฌ์ž๊ป˜์„œ ๋ฆฌ๋ทฐ๋ฅผ ํ•ด์ฃผ์‹œ๋ฉด ๊ทธ๊ฒƒ์„ ๋ฐ˜์˜ํ•˜์‹œ๋ฉด์„œ
์…€ํ”„ ๋ฆฌ๋ทฐ๋ฅผ ํ•œ๋ฒˆ ๋” ํ•˜์‹œ๋Š” ๊ฒƒ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
์ œ๊ฐ€ ํ† ์”จ ํ•˜๋‚˜ ๊ณฑ์”น์œผ๋ฉด์„œ ์ฝ์€ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์ •ํ™•์น˜ ์•Š์„ ์ˆ˜๋„ ์žˆ๊ฒ ์ง€๋งŒ
์ œ๊ฐ€ ๋ฆฌ๋ทฐ์— ๋ฏธ์ฒ˜ ๋ช…์‹œ์ ์œผ๋กœ ํ‘œ์‹œํ•˜์ง€ ๋ชปํ•˜๊ณ  ๋†“์นœ ๋ถ€๋ถ„๋“ค๋„ ๋ช‡ ๊ฐ€์ง€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. (๋„์–ด์“ฐ๊ธฐ๋ผ๋˜๊ฐ€.. ๋ฏธ์„ธํ•œ ๋‰˜์•™์Šค ๋“ฑ.)

์ €๋Š” ๊ฐœ์ธ์ ์œผ๋กœ ์ด ๋ฌธ์„œ ๋ฒˆ์—ญ ์ž‘์—…์„ ํ•˜๋ฉด์„œ ๊ธฐ์กด์— ๋ฒˆ์—ญ๋˜์–ด ์žˆ๋˜ ๋ฌธ์„œ๋“ค์„ ๋งŽ์ด ์ฐธ๊ณ ํ•˜๋ฉด์„œ
์˜๋ฏธ๋ฅผ ์ „๋‹ฌํ•˜๋Š” ์ „์ฒด์ ์ธ ํ†ค๊ณผ ๋‰˜์•™์Šค์— ๋งŽ์ด ์ดˆ์ ์„ ๋งž์ท„์—ˆ๊ณ , ๊ทธ๋ž˜์„œ ๋ฒˆ์—ญ ์ฐฉ์ˆ˜ํ•œ ๊ธฐ๊ฐ„์— ๋น„ํ•ด์„œ
(๋ฌผ๋ก  ๋‹ค๋ฅธ ๊ฐœ์ธ์ ์ธ ์ผ๋“ค์ด ์žˆ๊ธด ํ–ˆ์ง€๋งŒ) ์กฐ๊ธˆ ๋А๋ฆฌ๊ณ  ์˜ค๋ž˜๊ฑธ๋ฆฌ์ง€ ์•Š์•˜๋‚˜ ํ•˜๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค.

์šฐ์„  ์ž์„ธํ•œ ๋‚ด์šฉ๋“ค์€ ๋ฆฌ๋ทฐ์— ์žˆ์ง€๋งŒ ์ด ๋ฌธ์„œ ๋ฒˆ์—ญ ์ „๋ฐ˜์— ๊ฑธ์ณ
์ œ๊ฐ€ ๋ง์”€๋“œ๋ฆฌ๊ณ  ์‹ถ์€ ํฐ ์ค„๊ธฐ๋Š” ์ด๋ ‡์Šต๋‹ˆ๋‹ค.

  1. side effect๋ฅผ ๋ถ€์ž‘์šฉ์œผ๋กœ ๋ฒˆ์—ญ ํ›„ ๊ด„ํ˜ธ ์•ˆ์— ์˜๋ฌธ์„ ๋‚จ๊ฒจ๋‘์‹  ๊ฒƒ
  • ์ด ๊ฒƒ์€ ์›๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  1. argument๋ฅผ ์ธ์ˆ˜ ๋ผ๊ณ  ํ‘œํ˜„ํ•˜์‹  ๊ฒƒ.
  • ์ด ๋ถ€๋ถ„์€ ๊ฐœ์ธ์ ์œผ๋กœ ์ธ์ž ๊ฐ€ ๋งž๋Š” ํ‘œํ˜„์ด๋ผ๊ณ  ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค.
  1. ๋ด…์‹œ๋‹ค ์™€ ๊ฐ™์€ let's ~์˜ ๋ฐ˜ ๊ฐ•์ œ(?)๋‰˜์•™์Šค์˜ ๋ฒˆ์—ญ
  • ์ด ๊ฒƒ์€ ์กฐ๊ธˆ ๋” ๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์— ๊ฐ€๊น์ง€๋งŒ, ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค, ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์™€ ๊ฐ™์€ ์‹์˜ ๋‰˜์•™์Šค๊ฐ€ ๋” ๋งค๋„๋Ÿฝ๋‹ค๊ณ  ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค.

๋Œ€๊ฐ• ์ด์ •๋„์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๋‹ค๋ฅธ ๋ฌธ์„œ์— ๋น„ํ•ด์„œ ๋งค์šฐ ๊ธด ํŽธ์— ์†ํ•˜๋Š”๋ฐ, ๋ฒˆ์—ญํ•˜์‹œ๋А๋ผ ์ •๋ง ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค.
์ €๋„ ์ฒ˜์Œ ์ด ๋ฌธ์„œ ๋ฒˆ์—ญ์— ์ฐฉ์ˆ˜ํ•˜๋ฉด์„œ ๋ง‰๋ง‰ํ•œ ๋А๋‚Œ์ด ์กฐ๊ธˆ ๋“ค์—ˆ์—ˆ๊ฑฐ๋“ ์š”... ใ…‹ใ…‹
๊ณง ๋จธ์ง€๋˜์–ด react.org ์—์„œ ๋ฐ˜์˜๋œ ๋ฌธ์„œ๋กœ ๋งŒ๋‚ ์ˆ˜ ์žˆ๊ธธ ๊ธฐ๋Œ€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

Comment thread content/docs/hooks-effect.md Resolved
Comment on lines 89 to 95

Now let's see how we can do the same with the `useEffect` Hook.
์ด์ œ `useEffect` Hook์—์„œ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•˜๋Š”์ง€ ๋ด…์‹œ๋‹ค.

### Example Using Hooks {#example-using-hooks}
### Hook์„ ์ด์šฉํ•˜๋Š” ์˜ˆ์‹œ {#example-using-hooks}

We've already seen this example at the top of this page, but let's take a closer look at it:
์•„๋ž˜์˜ ์ฝ”๋“œ๋Š” ์œ„์—์„œ ์ด๋ฏธ ๋ณด์•˜๋˜ ๊ฒƒ์ด์ง€๋งŒ ์ด๋ฒˆ์—” ์ข€ ๋” ์ž์„ธํžˆ ๋“ค์—ฌ๋‹ค๋ด…์‹œ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋Š” ๋ฒˆ์—ญ ์ž‘์—…์„ ํ•˜๋ฉด์„œ ๊ธฐ์กด์— ๋ฒˆ์—ญ๋˜์–ด์žˆ๋˜ ๋ฌธ์„œ๋“ค์˜ ๋‰˜์•™์Šค๋ฅผ ๋งŽ์ด ์ฐธ๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค.
let's see ~ ํ˜น์€ let's take a look ~๊ณผ ๊ฐ™์€ ๋А๋‚Œ์€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ˜น์€ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์™€ ๊ฐ™์€ ๋‰˜์•™์Šค๋กœ ์ž‘์„ฑํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

Comment on lines 373 to 380
componentDidUpdate(prevProps) {
// Unsubscribe from the previous friend.id
// ์ด์ „ friend.id์—์„œ ๊ตฌ๋…์„ ํ•ด์ง€ํ•œ๋‹ค.
ChatAPI.unsubscribeFromFriendStatus(
prevProps.friend.id,
this.handleStatusChange
);
// Subscribe to the next friend.id
// ๋‹ค์Œ friend.id๋ฅผ ๊ตฌ๋…ํ•œ๋‹ค
ChatAPI.subscribeToFriendStatus(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„๋„ ์กด๋Œ“๋ง ๋‰˜์•™์Šค๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Comment thread content/docs/hooks-effect.md Outdated
Comment on lines +117 to +121
**`useEffect`๊ฐ€ ํ•˜๋Š” ์ผ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?** useEffect Hook์„ ์ด์šฉํ•˜์—ฌ ์šฐ๋ฆฌ๋Š” ๋ฆฌ์•กํŠธ์—๊ฒŒ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ์ดํ›„์— ์–ด๋–ค ์ผ์„ ์ˆ˜ํ–‰ํ•ด์•ผํ•˜๋Š” ์ง€๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค. ๋ฆฌ์•กํŠธ๋Š” ์šฐ๋ฆฌ๊ฐ€ ๋„˜๊ธด ํ•จ์ˆ˜๋ฅผ ๊ธฐ์–ตํ–ˆ๋‹ค๊ฐ€(์ด ํ•จ์ˆ˜๋ฅผ โ€˜effectโ€™๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค) DOM ์—…๋ฐ์ดํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•œ ์ดํ›„์— ๋ถˆ๋Ÿฌ๋‚ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ์ด effect๋ฅผ ํ†ตํ•ด ๋ฌธ์„œ ํƒ€์ดํ‹€์„ ์ง€์ •ํ•˜์ง€๋งŒ ์ด ์™ธ์—๋„ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ๋ช…๋ นํ˜•(imperative) API๋ฅผ ๋ถˆ๋Ÿฌ๋‚ด๋Š” ์ผ๋„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

**Why is `useEffect` called inside a component?** Placing `useEffect` inside the component lets us access the `count` state variable (or any props) right from the effect. We don't need a special API to read it -- it's already in the function scope. Hooks embrace JavaScript closures and avoid introducing React-specific APIs where JavaScript already provides a solution.
**`useEffect`๋ฅผ ์ปดํฌ๋„ŒํŠธ ์•ˆ์—์„œ ๋ถˆ๋Ÿฌ๋‚ด๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?** `useEffect`๋ฅผ ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์— ๋‘ ์œผ๋กœ์จ effect๋ฅผ ํ†ตํ•ด `count` state ๋ณ€์ˆ˜(๋˜๋Š” ๊ทธ ์–ด๋–ค prop์—๋„)์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ํ•จ์ˆ˜ ๋ฒ”์œ„ ์•ˆ์— ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํŠน๋ณ„ํ•œ API ์—†์ด๋„ ๊ฐ’์„ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Hook์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ํด๋กœ์ €๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฆฌ์•กํŠธ์— ํ•œ์ •๋œ API๋ฅผ ๊ณ ์•ˆํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ด๋ฏธ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

**Does `useEffect` run after every render?** Yes! By default, it runs both after the first render *and* after every update. (We will later talk about [how to customize this](#tip-optimizing-performance-by-skipping-effects).) Instead of thinking in terms of "mounting" and "updating", you might find it easier to think that effects happen "after render". React guarantees the DOM has been updated by the time it runs the effects.
**`useEffect`๋Š” ๋ Œ๋”๋ง ์ดํ›„์— ๋งค๋ฒˆ ์ˆ˜ํ–‰๋˜๋Š” ๊ฑด๊ฐ€์š”?** ๋„ค, ๊ธฐ๋ณธ์ ์œผ๋กœ ์ฒซ๋ฒˆ์งธ ๋ Œ๋”๋ง*๊ณผ* ์ดํ›„์˜ ๋ชจ๋“  ์—…๋ฐ์ดํŠธ์—์„œ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค.(๋‚˜์ค‘์— [effect๋ฅผ ํ•„์š”์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•](#tip-optimizing-performance-by-skipping-effects)์— ๋Œ€ํ•ด ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค.) ๋งˆ์šดํŒ…๊ณผ ์—…๋ฐ์ดํŠธ๋ผ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ƒ๊ฐํ•˜๋Š” ๋Œ€์‹  effect๋ฅผ ๋ Œ๋”๋ง ์ดํ›„์— ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ƒ๊ฐํ•˜๋Š” ๊ฒƒ์ด ๋” ์‰ฌ์šธ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฆฌ์•กํŠธ๋Š” effect๊ฐ€ ์ˆ˜ํ–‰๋˜๋Š” ์‹œ์ ์— ์ด๋ฏธ DOM์ด ์—…๋ฐ์ดํŠธ๋˜์—ˆ์Œ์„ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L227, L229์— ์‚ฌ์šฉํ•˜์‹  ๊ฒƒ์ฒ˜๋Ÿผ ~์ผ๊นŒ์š”? ์™€ ๊ฐ™์€ ๋‰˜์•™์Šค๊ฐ€ ๋”์šฑ ์ฝ๊ธฐ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

Comment thread content/docs/hooks-effect.md Outdated
>ํŒ
>
>Unlike `componentDidMount` or `componentDidUpdate`, effects scheduled with `useEffect` don't block the browser from updating the screen. This makes your app feel more responsive. The majority of effects don't need to happen synchronously. In the uncommon cases where they do (such as measuring the layout), there is a separate [`useLayoutEffect`](/docs/hooks-reference.html#uselayouteffect) Hook with an API identical to `useEffect`.
>`componentDidMount`๋‚˜ `componentDidUpdate`์™€๋Š” ๋‹ฌ๋ฆฌ `useEffect`์—์„œ ์‚ฌ์šฉ๋˜๋Š” effect๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ํ™”๋ฉด์ด ์—…๋ฐ์ดํŠธ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉํ•ดํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ข€ ๋” ๋ฐ˜์‘ํ˜•์œผ๋กœ ๋ณด์ผ ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ effect๋Š” ๋™๊ธฐ์  ์‹คํ–‰์ด ํ•„์š”์—†์Šต๋‹ˆ๋‹ค. ๋™๊ธฐ์  ์‹คํ–‰์ด ํ•„์š”ํ•œ ๋“œ๋ฌธ ๊ฒฝ์šฐ๋“ค(๋ ˆ์ด์•„์›ƒ์˜ ๊ณ„์‚ฐ๊ณผ ๊ฐ™์€)์€ `useEffect`๊ณผ ๋™์ผํ•œ [`useLayoutEffect`](/docs/hooks-reference.html#uselayouteffect) Hook์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ˜์‘ํ˜•์œผ๋กœ ๋ณด์ผ์ˆ˜ ์žˆ๊ฒŒ ์™€ ๊ฐ™์€ ๋ถ€๋ถ„์€ ์‘๋‹ต์„ฑ ํ˜น์€ ๋ฐ˜์‘์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚จ๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ๋˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์•„๋ž˜๋Š” ์ œ๊ฐ€ ์ž‘์„ฑํ–ˆ๋˜ ๋ฒˆ์—ญ์ž…๋‹ˆ๋‹ค. ์ฐธ๊ณ ๊ฐ€ ๋˜์‹ค๊นŒ ํ•ด์„œ ์ฒจ๋ถ€ํ•ฉ๋‹ˆ๋‹ค.

componentDidMount ํ˜น์€ componentDidUpdate ์™€๋Š” ๋‹ฌ๋ฆฌ useEffect๋ฅผ ํ†ตํ•ด ์˜ˆ์•ฝ๋œ effect๋Š” ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ํ™”๋ฉด์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒƒ์„ ์ฐจ๋‹จํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์•ฑ์˜ ์‘๋‹ต์„ฑ์„ ๋”์šฑ ํ–ฅ์ƒ์‹œ์ผœ์ค๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ effect๋“ค์€ ๋™๊ธฐ์ ์œผ๋กœ ๋ฐœ์ƒํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ํ”ํ•œ ๊ฒฝ์šฐ๋Š” ์•„๋‹ˆ์ง€๋งŒ (๋ ˆ์ด์•„์›ƒ ์ธก์ •๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ) useEffect์™€ ๋™์ผํ•œ API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” useLayoutEffect ๋ผ๋Š” ๋ณ„๋„์˜ Hook์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

@yumidev yumidev Feb 9, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฒจ๋ถ€ํ•ด์ฃผ์‹  ๋‚ด์šฉ์„ ์ƒ๋‹น ๋ถ€๋ถ„ ๋ฐ˜์˜ํ•ด์„œ ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

componentDidMount ํ˜น์€ componentDidUpdate์™€๋Š” ๋‹ฌ๋ฆฌ useEffect์—์„œ ์‚ฌ์šฉ๋˜๋Š” effect๋Š” ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ํ™”๋ฉด์„ ์—…๋ฐ์ดํŠธ๋˜๋Š” ๊ฒƒ์„ ์ฐจ๋‹จํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ฐ˜์‘์„ฑ์„ ํ–ฅ์ƒ์‹œ์ผœ์ค๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ effect๋“ค์€ ๋™๊ธฐ์ ์œผ๋กœ ์‹คํ–‰๋  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ํ”ํ•˜์ง€๋Š” ์•Š์ง€๋งŒ (๋ ˆ์ด์•„์›ƒ์˜ ์ธก์ •๊ณผ ๊ฐ™์€) ๋™๊ธฐ์  ์‹คํ–‰์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” useEffect์™€ ๋™์ผํ•œ API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” useLayoutEffect๋ผ๋Š” ๋ณ„๋„์˜ Hook์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

Comment on lines 271 to 273

### Tip: Use Multiple Effects to Separate Concerns {#tip-use-multiple-effects-to-separate-concerns}
### ํŒ: ๊ด€์‹ฌ์‚ฌ๋ฅผ ๊ตฌ๋ถ„ํ•˜๋ ค๊ณ  ํ•œ๋‹ค๋ฉด Multiple Effect๋ฅผ ์‚ฌ์šฉํ•˜๋ผ{#tip-use-multiple-effects-to-separate-concerns}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ๋„ ์กด๋Œ“๋ง ๋‰˜์•™์Šค๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด ์ข‹์ง€ ์•Š์„๊นŒ ํ•˜๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

Comment on lines 482 to 484

## Next Steps {#next-steps}
## ๋‹ค์Œ ์ˆœ์„œ {#next-steps}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‹ค๋ฅธ ๋ฒˆ์—ญ๋ณธ์„ ์ฐธ๊ณ ํ•ด๋ดค์„ ๋•Œ, ๋‹ค์Œ ๋‹จ๊ณ„๋ผ๋Š” ํ‘œํ˜„์ด ๋” ๋งž๋Š” ํ‘œํ˜„์ผ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Comment thread content/docs/hooks-effect.md Outdated
```

In the future, the second argument might get added automatically by a build-time transformation.
๋‘๋ฒˆ์งธ ์ธ์ˆ˜๋Š” ์žฅ์ฐจ build-time ๋ณ€ํ™˜์— ์˜ํ•ด ์ž๋™์œผ๋กœ ๋”ํ•ด์งˆ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‘ ๋ฒˆ์งธ ์ธ์ž๋Š” ๋นŒ๋“œ ์‹œ ๋ณ€ํ™˜์— ์˜ํ•ด ์ž๋™์œผ๋กœ ์ถ”๊ฐ€๋  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์ธ์ˆ˜ ==> ์ธ์ž

build time ==> ๋นŒ๋“œ ์‹œ

์žฅ์ฐจ ==> (์‚ญ์ œ)

์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Comment thread content/docs/hooks-effect.md Outdated
### ํŒ: Effect๋ฅผ ๊ฑด๋„ˆ๋›ฐ์–ด ์„ฑ๋Šฅ ์ตœ์ ํ™”ํ•˜๊ธฐ {#tip-optimizing-performance-by-skipping-effects}

In some cases, cleaning up or applying the effect after every render might create a performance problem. In class components, we can solve this by writing an extra comparison with `prevProps` or `prevState` inside `componentDidUpdate`:
๋ชจ๋“  ๋ Œ๋”๋ง ์ดํ›„์— effect๋ฅผ ์ •๋ฆฌ(clean-up)ํ•˜๊ฑฐ๋‚˜ ์ ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋•Œ๋•Œ๋กœ ํผํฌ๋จผ์Šค ์ด์Šˆ(์„ฑ๋Šฅ์ €ํ•˜)๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์˜ ๊ฒฝ์šฐ์—๋Š” `componentDidUpdate`์—์„œ `prevProps`๋‚˜ `prevState`์™€์˜ ๋น„๊ต๋ฅผ ํ†ตํ•ด ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํผํฌ๋จผ์Šค ์ด์Šˆ ๋Š” ์‚ญ์ œํ•˜๊ณ  ์„ฑ๋Šฅ ์ €ํ•˜๋ผ๊ณ ๋งŒ ์ž‘์„ฑํ•˜์…”๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Comment thread content/docs/hooks-effect.md Outdated
>์ฃผ์˜
>
>If you use this optimization, make sure the array includes **all values from the component scope (such as props and state) that change over time and that are used by the effect**. Otherwise, your code will reference stale values from previous renders. Learn more about [how to deal with functions](/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies) and [what to do when the array changes too often](/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often).
>์ด ์ตœ์ ํ™” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ฐฐ์—ด์ด **์ปดํฌ๋„ŒํŠธ ๋ฒ”์œ„ ๋‚ด์—์„œ ๋ฐ”๋€Œ๋Š” ๊ฐ’๋“ค๊ณผ effect์— ์˜ํ•ด ์‚ฌ์šฉ๋˜๋Š” ๊ฐ’๋“ค์„ ๋ชจ๋‘ ํฌํ•จํ•˜๋Š” ๊ฒƒ**์„ ์žŠ์ง€ ๋ง์•„์ฃผ์„ธ์š”. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ํ˜„์žฌ ๊ฐ’์ด ์•„๋‹Œ ์ด์ „์˜ ๋ Œ๋”๋ง ๋•Œ์˜ ๊ฐ’์„ ์ฐธ๊ณ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด์— ๋Œ€ํ•ด์„œ๋Š” [ํ•จ์ˆ˜๋ฅผ ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•](/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies)๊ณผ [์˜์กด์„ฑ ๊ฐ’ ๋ฐฐ์—ด์ด ์ž์ฃผ ๋ฐ”๋€” ๋•Œ๋Š” ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ•˜๋Š”๊ฐ€](/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often)์—์„œ ๋” ์ž์„ธํžˆ ์•Œ์•„๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์žŠ์ง€ ๋ง์•„์ฃผ์„ธ์š” ==> ๊ธฐ์–ตํ•ด์ฃผ์„ธ์š”
์˜์กด์„ฑ ๊ฐ’ ๋ฐฐ์—ด ==> ์˜์กด์„ฑ ๋ฐฐ์—ด

๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝ๋˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@anthonyminyungi

anthonyminyungi commented Feb 10, 2020 •

Copy link
Copy Markdown
Contributor

์•Œ๋ฆผ์ด ์™€์„œ ์ƒˆ๋กœ ์ˆ˜์ •ํ•˜์—ฌ ์ปค๋ฐ‹ํ•˜์‹  ๋‚ด์šฉ์„ ํ™•์ธํ–ˆ๋Š”๋ฐ, ์ œ๊ฐ€ ๋ฆฌ๋ทฐํ•œ ๋‚ด์šฉ์„ ๋ฉด๋ฐ€ํ•˜๊ฒŒ ๋ฐ˜์˜ํ•ด์ฃผ์…จ๋”๋ผ๊ตฌ์š”!
๋ฐ›์•„๋“ค์—ฌ์ฃผ์…”์„œ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์ฝ๊ธฐ์—๋Š” ๊ต‰์žฅํžˆ ๋งค๋„๋Ÿฌ์šด ๋ฒˆ์—ญ์ด ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!
๋ฉ”์ธํ…Œ์ด๋„ˆ๋ถ„๋“ค์ด ํ•œ๋ฒˆ ๋” ์ฒดํฌํ•ด์ฃผ์‹œ๊ณ  approval ์ฃผ์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@yumidev

yumidev commented Mar 1, 2020

Copy link
Copy Markdown
Contributor Author

์•Œ๋ฆผ์ด ์™€์„œ ์ƒˆ๋กœ ์ˆ˜์ •ํ•˜์—ฌ ์ปค๋ฐ‹ํ•˜์‹  ๋‚ด์šฉ์„ ํ™•์ธํ–ˆ๋Š”๋ฐ, ์ œ๊ฐ€ ๋ฆฌ๋ทฐํ•œ ๋‚ด์šฉ์„ ๋ฉด๋ฐ€ํ•˜๊ฒŒ ๋ฐ˜์˜ํ•ด์ฃผ์…จ๋”๋ผ๊ตฌ์š”!
๋ฐ›์•„๋“ค์—ฌ์ฃผ์…”์„œ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์ฝ๊ธฐ์—๋Š” ๊ต‰์žฅํžˆ ๋งค๋„๋Ÿฌ์šด ๋ฒˆ์—ญ์ด ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!
๋ฉ”์ธํ…Œ์ด๋„ˆ๋ถ„๋“ค์ด ํ•œ๋ฒˆ ๋” ์ฒดํฌํ•ด์ฃผ์‹œ๊ณ  approval ์ฃผ์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์—…๋ฐ์ดํŠธ ํ™•์ธํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ํ˜น์—ฌ ๋ชจ๋ฅด๋‹ˆ ์˜ค๋Š˜ ๋งž์ถค๋ฒ• ๊ฒ€์‚ฌ๋ฅผ ํ•œ๋ฒˆ ๋” ์ง„ํ–‰ํ•˜๊ณ  approval์— ํ•„์š”ํ•œ ์ˆœ์„œ๋ฅผ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฆฌ๋ทฐ ์ •๋ง ๊ฐ์‚ฌํ•ด์š”!

@hg-pyun hg-pyun left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anthonyminyungi ๋‹˜๊ป˜์„œ ๊ต‰์žฅํžˆ ์ž˜ ๋ณด์•„์ฃผ์…”์„œ, ๋”ฐ๋กœ ๋” ์ฝ”๋ฉ˜ํŠธ ํ•  ๊ฑด ์—†์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
@yumidev ๋ฒˆ์—ญํ•˜๋А๋ผ ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!

@hg-pyun
hg-pyun merged commit 970a44f into reactjs:master Mar 6, 2020
@hg-pyun

hg-pyun commented Mar 6, 2020

Copy link
Copy Markdown
Member

๋”ฑํžˆ ๋งž์ถค๋ฒ•๋„ ๋ฌธ์ œ์—†์–ด ๋ณด์ด๋ฏ€๋กœ ๋จธ์ง€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants