We want to hear from you!Take our 2021 Community Survey!
This site is no longer updated.Go to react.dev

React ์ตœ์ƒ์œ„ API

These docs are old and wonโ€™t be updated. Go to react.dev for the new React docs.

These new documentation pages teach modern React:

React๋Š” React ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ง„์ž…์ ์ž…๋‹ˆ๋‹ค. <script> ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ React๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ฒŒ ๋˜๋ฉด ์ „์—ญ ๊ฐ์ฒด React๋ฅผ ํ†ตํ•˜์—ฌ ์ตœ์ƒ์œ„ API๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. npm์—์„œ ES6๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, import React from 'react'๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. npm์—์„œ ES5๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, var React = require('react')๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๊ฐœ์š”

์ปดํฌ๋„ŒํŠธ

React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด UI๋ฅผ ๋…๋ฆฝ์ ์ด๊ณ  ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆ„๊ณ  ๊ฐ ๋ถ€๋ถ„์„ ๋ถ„๋ฆฌํ•˜์—ฌ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. React ์ปดํฌ๋„ŒํŠธ๋Š” React.Component ๋˜๋Š” React.PureComponent๋กœ ์„ธ๋ถ€์ ์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ES6 class๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, create-react-class ๋ชจ๋“ˆ์„ ๋Œ€์‹  ์‚ฌ์šฉํ•ด๋„ ๋ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ์ •๋ณด๋Š” ES6 ์—†์ด React๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋ฌธ์„œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•  ๋•Œ ๋ž˜ํ•‘๋  ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜์˜ ํ˜•ํƒœ๋กœ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

React ์—˜๋ฆฌ๋จผํŠธ ์ƒ์„ฑํ•˜๊ธฐ

UI์˜ ํ˜•ํƒœ๋ฅผ ์„ค๋ช…ํ•˜๋Š” ๋ฐ์— JSX๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. ๊ฐ JSX ์—˜๋ฆฌ๋จผํŠธ๋Š” ๋‹จ์ง€ React.createElement()๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ํŽธ๋ฆฌํ•œ ๋ฌธ๋ฒ•์— ๋ถˆ๊ณผํ•ฉ๋‹ˆ๋‹ค. JSX๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์•„๋ž˜์˜ ๋ฉ”์„œ๋“œ๋“ค์„ ์ง์ ‘ ํ˜ธ์ถœํ•˜๋Š” ์ผ์€ ๊ฑฐ์˜ ์—†์Šต๋‹ˆ๋‹ค.

์ž์„ธํ•œ ์ •๋ณด๋Š” JSX ์—†์ด React ์‚ฌ์šฉํ•˜๊ธฐ ๋ฌธ์„œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์—˜๋ฆฌ๋จผํŠธ ๋ณ€ํ™˜ํ•˜๊ธฐ

React๋Š” ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์กฐ์ž‘ํ•˜๋Š” API๋“ค์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Fragments

๋˜ํ•œ React๋Š” ๋ž˜ํผ ์—†์ด ์—ฌ๋Ÿฌ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Refs

Suspense

Suspense๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋งํ•˜๊ธฐ ์ „์— ๋‹ค๋ฅธ ์ž‘์—…์ด ๋จผ์ € ์ด๋ฃจ์–ด์ง€๋„๋ก โ€œ๋Œ€๊ธฐํ•ฉ๋‹ˆ๋‹คโ€. ํ˜„์žฌ Suspense๋Š” ๋‹จ ํ•˜๋‚˜์˜ ์‚ฌ์šฉ ์‚ฌ๋ก€ React.lazy๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋™์ ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ๋‚˜์ค‘์—๋Š” ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ์™€ ๊ฐ™์€ ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ง€์›ํ•  ๊ณ„ํš์ž…๋‹ˆ๋‹ค.

Transitions

Transitions๋Š” React 18์— ๋„์ž…๋œ ์ƒˆ๋กœ์šด ๋™์‹œ(concurrent) ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. ์ด๋Š” ์—…๋ฐ์ดํŠธ๋ฅผ transitions์œผ๋กœ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์—ฌ React์—๊ฒŒ ์ค‘๋‹จ๋  ์ˆ˜ ์žˆ์Œ์„ ์•Œ๋ฆฌ๊ณ , ์ด๋ฏธ ๋ณด์ด๋Š” ์ฝ˜ํ…์ธ ์— ๋Œ€ํ•ด Suspense Fallback์œผ๋กœ ๊ฐ€๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Hooks

Hooks๋Š” React 16.8์— ์ƒˆ๋กœ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Hooks๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด class๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ state์™€ React ๊ธฐ๋Šฅ๋“ค์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค. Hooks๋งŒ์„ ๋‹ค๋ฃจ๋Š” ๋ฌธ์„œ์™€ API ๋ฌธ์„œ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.


Reference

React.Component

This content is out of date.

Read the new React documentation for Component.

React.Component๋Š” ES6 class๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•  ๋•Œ์— ๊ธฐ์ดˆ๊ฐ€ ๋˜๋Š” class์ž…๋‹ˆ๋‹ค.

class Greeting extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}

React.Component ๊ธฐ์ดˆ class์™€ ๊ด€๋ จ๋œ ๋ฉ”์„œ๋“œ์™€ ์†์„ฑ ๋ชฉ๋ก์€ React.Component API Reference์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


React.PureComponent

This content is out of date.

Read the new React documentation for PureComponent.

React.PureComponent๋Š” React.Component์™€ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค. React.Component๋Š” shouldComponentUpdate()๋ฅผ ๊ตฌํ˜„ํ•˜์ง€ ์•Š์ง€๋งŒ, React.PureComponent๋Š” props์™€ state๋ฅผ ์ด์šฉํ•œ ์–•์€ ๋น„๊ต๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค๋Š” ์ฐจ์ด์ ๋งŒ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

React ์ปดํฌ๋„ŒํŠธ์˜ render() ํ•จ์ˆ˜๊ฐ€ ๋™์ผํ•œ props์™€ state์— ๋Œ€ํ•˜์—ฌ ๋™์ผํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ Œ๋”๋งํ•œ๋‹ค๋ฉด, React.PureComponent๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒฝ์šฐ์— ๋”ฐ๋ผ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ๋ˆ„๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฃผ์˜

React.PureComponent์˜ shouldComponentUpdate()๋Š” ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•˜์—ฌ ์–•์€ ๋น„๊ต๋งŒ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ปดํฌ๋„ŒํŠธ์— ๋ณต์žกํ•œ ์ž๋ฃŒ ๊ตฌ์กฐ๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋‹ค๋ฉด, ๊นŠ์€ ์ฐจ์ด๊ฐ€ ์กด์žฌํ•จ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ์ฐจ์ด๊ฐ€ ์—†๋‹ค๊ณ  ํŒ๋‹จํ•˜๋Š” ์ž˜๋ชป๋œ ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค์–ด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. props์™€ state์˜ ๊ตฌ์กฐ๊ฐ€ ๊ฐ„๋‹จํ•  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋  ๋•Œ์—๋งŒ PureComponent๋ฅผ ์ƒ์†ํ•˜๊ณ , ๊นŠ์€ ์ž๋ฃŒ ๊ตฌ์กฐ์˜ ๋ณ€ํ™”๊ฐ€ ์žˆ๋‹ค๋ฉด forceUpdate()๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”. ๋˜๋Š” ์ค‘์ฒฉ๋œ ๋ฐ์ดํ„ฐ๋“ค์„ ๋น ๋ฅด๊ฒŒ ๋น„๊ตํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ ค๋ฉด ๋ถˆ๋ณ€ ๊ฐ์ฒด์˜ ์‚ฌ์šฉ์„ ๊ฒ€ํ† ํ•ด๋ณด์„ธ์š”.

๋” ๋‚˜์•„๊ฐ€ React.PureComponent์˜ shouldComponentUpdate()๋Š” ์ปดํฌ๋„ŒํŠธ์˜ ํ•˜์œ„ ํŠธ๋ฆฌ์— ๋Œ€ํ•œ props ๊ฐฑ์‹  ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋“ค์ด โ€œ์ˆœ์ˆ˜โ€ํ•œ์ง€ ๊ผญ ํ™•์ธํ•˜๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.


React.memo

This content is out of date.

Read the new React documentation for memo.

const MyComponent = React.memo(function MyComponent(props) {
  /* props๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ Œ๋”๋ง */
});

React.memo๋Š” ๊ณ ์ฐจ ์ปดํฌ๋„ŒํŠธ(Higher Order Component)์ž…๋‹ˆ๋‹ค.

์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋™์ผํ•œ props๋กœ ๋™์ผํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ Œ๋”๋งํ•ด๋‚ธ๋‹ค๋ฉด, React.memo๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”๋ชจ์ด์ง•(Memoizing)ํ•˜๋„๋ก ๋ž˜ํ•‘ํ•˜์—ฌ ๊ฒฝ์šฐ์— ๋”ฐ๋ผ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ๋ˆ„๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฆ‰, React๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜์ง€ ์•Š๊ณ  ๋งˆ์ง€๋ง‰์œผ๋กœ ๋ Œ๋”๋ง๋œ ๊ฒฐ๊ณผ๋ฅผ ์žฌ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

React.memo๋Š” props ๋ณ€ํ™”์—๋งŒ ์˜ํ–ฅ์„ ์ค๋‹ˆ๋‹ค. React.memo๋กœ ๊ฐ์‹ธ์ง„ ํ•จ์ˆ˜ ์ปดํฌ๋„ŒํŠธ ๊ตฌํ˜„์— useState, useReducer ๋˜๋Š” useContext ํ›…์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ์—ฌ์ „ํžˆ state๋‚˜ context๊ฐ€ ๋ณ€ํ•  ๋•Œ ๋‹ค์‹œ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค.

props๊ฐ€ ๊ฐ–๋Š” ๋ณต์žกํ•œ ๊ฐ์ฒด์— ๋Œ€ํ•˜์—ฌ ์–•์€ ๋น„๊ต๋งŒ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์ด ๊ธฐ๋ณธ ๋™์ž‘์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋น„๊ต ๋™์ž‘์„ ์›ํ•œ๋‹ค๋ฉด, ๋‘ ๋ฒˆ์งธ ์ธ์ž๋กœ ๋ณ„๋„์˜ ๋น„๊ต ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

function MyComponent(props) {
  /* props๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ Œ๋”๋ง */
}
function areEqual(prevProps, nextProps) {
  /*
  nextProps๊ฐ€ prevProps์™€ ๋™์ผํ•œ ๊ฐ’์„ ๊ฐ€์ง€๋ฉด true๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , ๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด false๋ฅผ ๋ฐ˜ํ™˜
  */
}
export default React.memo(MyComponent, areEqual);

์ด ๋ฉ”์„œ๋“œ๋Š” ์˜ค์ง ์„ฑ๋Šฅ ์ตœ์ ํ™”๋ฅผ ์œ„ํ•˜์—ฌ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ๋ Œ๋”๋ง์„ โ€œ๋ฐฉ์ง€โ€ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ์„ธ์š”. ๋ฒ„๊ทธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฃผ์˜

class ์ปดํฌ๋„ŒํŠธ์˜ shouldComponentUpdate() ๋ฉ”์„œ๋“œ์™€ ๋‹ฌ๋ฆฌ, areEqual ํ•จ์ˆ˜๋Š” props๋“ค์ด ์„œ๋กœ ๊ฐ™์œผ๋ฉด true๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , props๋“ค์ด ์„œ๋กœ ๋‹ค๋ฅด๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ shouldComponentUpdate์™€ ์ •๋ฐ˜๋Œ€์˜ ๋™์ž‘์ž…๋‹ˆ๋‹ค.


createElement()

This content is out of date.

Read the new React documentation for createElement.

React.createElement(
  type,
  [props],
  [...children]
)

์ธ์ž๋กœ ์ฃผ์–ด์ง€๋Š” ํƒ€์ž…์— ๋”ฐ๋ผ ์ƒˆ๋กœ์šด React ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. type ์ธ์ž๋กœ๋Š” ํƒœ๊ทธ ์ด๋ฆ„ ๋ฌธ์ž์—ด('div' ๋˜๋Š” 'span' ๋“ฑ), React ์ปดํฌ๋„ŒํŠธ ํƒ€์ž…, ๋˜๋Š” React Fragment ํƒ€์ž… ์ค‘ ํ•˜๋‚˜๊ฐ€ ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

JSX๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๋Š” React.createElement()๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค. JSX๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ React.createElement()๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•˜๋Š” ์ผ์€ ๊ฑฐ์˜ ์—†์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ์ •๋ณด๋Š” JSX ์—†์ด React ์‚ฌ์šฉํ•˜๊ธฐ ๋ฌธ์„œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


cloneElement()

This content is out of date.

Read the new React documentation for cloneElement.

React.cloneElement(
  element,
  [config],
  [...children]
)

element๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ƒˆ๋กœ์šด React ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ณต์‚ฌํ•˜๊ณ  ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. config๋Š” key์™€ ref ๊ทธ๋ฆฌ๊ณ  ๋ชจ๋“  ์ƒˆ๋กœ์šด props๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ์—˜๋ฆฌ๋จผํŠธ์—๋Š” ์›๋ณธ ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ๊ฐ€์กŒ๋˜ props๊ฐ€ ์ƒˆ๋กœ์šด props์™€ ์–•๊ฒŒ ํ•ฉ์ณ์ง„ ๋’ค ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ์ž์‹๋“ค์€ ๊ธฐ์กด์˜ ์ž์‹๋“ค์„ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค. config์— key์™€ ref๊ฐ€ ์—†๋‹ค๋ฉด ์›๋ณธ ์—˜๋ฆฌ๋จผํŠธ์˜ key์™€ ref๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.

React.cloneElement()๋Š” ์•„๋ž˜์˜ ๊ตฌ๋ฌธ๊ณผ ๊ฑฐ์˜ ๋™๋“ฑํ•ฉ๋‹ˆ๋‹ค.

<element.type {...element.props} {...props}>{children}</element.type>

๊ทธ๋ ‡์ง€๋งŒ ref๋“ค์ด ์œ ์ง€๋œ๋‹ค๋Š” ์ ์ด ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ์ฆ‰ ์กฐ์ƒ์ด ๊ฐ€์ง€๊ณ  ์žˆ์„ ref๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž์‹ ์—˜๋ฆฌ๋จผํŠธ์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์ด ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ์—˜๋ฆฌ๋จผํŠธ์— ๋ง๋ถ™์—ฌ์ง€๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•œ ref๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ref ๋˜๋Š” key๊ฐ€ ์žˆ๋‹ค๋ฉด ์ด์ „ ๊ฐ’์„ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค.

์ด API๋Š” ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” React.addons.cloneWithProps()๋ฅผ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค.


createFactory()

This content is out of date.

Read the new React documentation for createFactory.

React.createFactory(type)

์ฃผ์–ด์ง„ ํƒ€์ž…์˜ React ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋‚ด๋Š” ํ•จ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. React.createElement()์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ type ์ธ์ž๋Š” ํƒœ๊ทธ ์ด๋ฆ„ ๋ฌธ์ž์—ด('div' ๋˜๋Š” 'span' ๋“ฑ), React ์ปดํฌ๋„ŒํŠธ ํƒ€์ž…, ๋˜๋Š” React Fragment ํƒ€์ž… ์ค‘ ํ•˜๋‚˜๊ฐ€ ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ํ—ฌํผ ํ•จ์ˆ˜๋Š” ๋ ˆ๊ฑฐ์‹œ ๊ธฐ๋Šฅ์œผ๋กœ ๊ฐ„์ฃผ๋˜๋ฉฐ, ๋Œ€์‹  JSX ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ React.createElement()๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

JSX๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ React.createFactory()๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•˜๋Š” ์ผ์€ ๊ฑฐ์˜ ์—†์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ์ •๋ณด๋Š” JSX ์—†์ด React ์‚ฌ์šฉํ•˜๊ธฐ ๋ฌธ์„œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


isValidElement()

This content is out of date.

Read the new React documentation for isValidElement.

React.isValidElement(object)

๊ฐ์ฒด๊ฐ€ React ์—˜๋ฆฌ๋จผํŠธ์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. true ๋˜๋Š” false๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.


React.Children

This content is out of date.

Read the new React documentation for Children.

React.Children๋Š” ๋ถˆํˆฌ๋ช…(Opaque) ์ž๋ฃŒ ๊ตฌ์กฐ์ธ this.props.children๋ฅผ ๋‹ค๋ฃจ๋Š” ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜๋“ค์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

React.Children.map

React.Children.map(children, function[(thisArg)])

children์— ํฌํ•จ๋œ ๊ฐ ์ž์‹์— ๋Œ€ํ•˜์—ฌ this๋ฅผ thisArg์˜ ๊ฐ’์œผ๋กœ ์„ค์ •ํ•œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. children์ด ๋ฐฐ์—ด์ผ ๊ฒฝ์šฐ, ์ด ๋ฐฐ์—ด์˜ ๊ฐ ์ž์‹์— ๋Œ€ํ•˜์—ฌ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค. children์ด null ๋˜๋Š” undefined์ผ ๊ฒฝ์šฐ, ์ด ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์ด ์•„๋‹ˆ๋ผ null ๋˜๋Š” undefined๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์ฃผ์˜

children์ด Fragment์ผ ๊ฒฝ์šฐ, children์€ ๋‹จ์ผ ์ž์‹์œผ๋กœ ์ทจ๊ธ‰๋˜์–ด ์ˆœํšŒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

React.Children.forEach

React.Children.forEach(children, function[(thisArg)])

React.Children.map()์™€ ๋น„์Šทํ•˜์ง€๋งŒ, ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

React.Children.count

React.Children.count(children)

children์— ํฌํ•จ๋œ ์ปดํฌ๋„ŒํŠธ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. map ๋˜๋Š” forEach๋กœ ์ „๋‹ฌ๋œ ์ฝœ๋ฐฑ์ด ํ˜ธ์ถœ๋œ ํšŸ์ˆ˜์™€ ๋™์ผํ•œ ๊ฐ’์ž…๋‹ˆ๋‹ค.

React.Children.only

React.Children.only(children)

children์ด ๋‹จ ํ•˜๋‚˜์˜ ์ž์‹(React ์—˜๋ฆฌ๋จผํŠธ)๋ฅผ ๊ฐ–๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ํ•ด๋‹น ์ž์‹ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์„ ๊ฒฝ์šฐ ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค.

์ฃผ์˜

React.Children.only()๋Š” React.Children.map()์˜ ๋ฐ˜ํ™˜๊ฐ’์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋ฐ, ์™œ๋ƒํ•˜๋ฉด ๋ฐ˜ํ™˜๊ฐ’์ด React ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ์•„๋‹ˆ๋ผ ๋ฐฐ์—ด์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

React.Children.toArray

React.Children.toArray(children)

๊ฐ ์ž์‹์— key๊ฐ€ ํ• ๋‹น๋œ ๋ฐฐ์—ด์„ children ๋ถˆํˆฌ๋ช…(opaque) ์ž๋ฃŒ ๊ตฌ์กฐ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. render() ๋ฉ”์„œ๋“œ์—์„œ children์˜ ์ง‘ํ•ฉ์„ ๋‹ค๋ฃจ๊ณ  ์‹ถ์„ ๋•Œ, ํŠนํžˆ this.props.children์„ ํ•˜๋ถ€๋กœ ์ „๋‹ฌํ•˜๊ธฐ ์ „์— ๋‹ค์‹œ ์ •๋ ฌํ•˜๊ฑฐ๋‚˜ ์ผ๋ถ€๋งŒ ์ž˜๋ผ๋‚ด๊ณ  ์‹ถ์„ ๋•Œ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

์ฃผ์˜

React.Children.toArray()๋Š” children์„ ํ‰ํ‰ํ•˜๊ฒŒ(Flatten) ๋งŒ๋“ค ๋•Œ, ์ค‘์ฒฉ๋œ ๋ฐฐ์—ด๋“ค์˜ ์˜๋ฏธ๋ฅผ ๋ณด์กดํ•˜๊ธฐ ์œ„ํ•˜์—ฌ key๋ฅผ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, toArray๋Š” ๋ฐ˜ํ™˜๋˜๋Š” ๋ฐฐ์—ด์— key ๊ฐ’์„ ๋ง๋ถ™์—ฌ์„œ ๊ฐ ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ๊ฐ–๋Š” key๊ฐ€ ํ‰ํ‰ํ•ด์ง„ ๋ฐฐ์—ด ๋‚ด์—์„œ๋งŒ ์œ ํšจํ•œ ๋ฒ”์œ„๋ฅผ ํ˜•์„ฑํ•˜๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค.


React.Fragment

This content is out of date.

Read the new React documentation for Fragment.

React.Fragment ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด render() ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ ์ถ”๊ฐ€์ ์ธ DOM ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์•„๋„ ์—ฌ๋Ÿฌ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

render() {
  return (
    <React.Fragment>
      Some text.
      <h2>A heading</h2>
    </React.Fragment>
  );
}

์ถ•์•ฝํ˜•์ธ <></> ๋ฌธ๋ฒ•์œผ๋กœ๋„ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ์ •๋ณด๋Š” React v16.2.0: Fragment์— ๋Œ€ํ•œ ํ–ฅ์ƒ๋œ ์ง€์›์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

React.createRef

This content is out of date.

Read the new React documentation for createRef.

React.createRef๋Š” React ์—˜๋ฆฌ๋จผํŠธ์— ref ์–ดํŠธ๋ฆฌ๋ทฐํŠธ๋กœ ๋ถ™์ผ ์ˆ˜ ์žˆ๋Š” ref๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

class MyComponent extends React.Component {
  constructor(props) {
    super(props);

    this.inputRef = React.createRef();  }

  render() {
    return <input type="text" ref={this.inputRef} />;  }

  componentDidMount() {
    this.inputRef.current.focus();  }
}

React.forwardRef

This content is out of date.

Read the new React documentation for forwardRef.

React.forwardRef๋Š” ์ „๋‹ฌ๋ฐ›์€ ref ์–ดํŠธ๋ฆฌ๋ทฐํŠธ๋ฅผ ํ•˜๋ถ€ ํŠธ๋ฆฌ ๋‚ด์˜ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๋กœ ์ „๋‹ฌํ•˜๋Š” React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ธฐ๋ฒ•์€ ์ž˜ ์‚ฌ์šฉ๋˜์ง€ ์•Š์ง€๋งŒ, ์•„๋ž˜์˜ ๋‘ ์‹œ๋‚˜๋ฆฌ์˜ค์—์„œ๋Š” ํŠนํžˆ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

React.forwardRef๋Š” ๋ Œ๋”๋ง์— ์‚ฌ์šฉ๋  ํ•จ์ˆ˜๋ฅผ ์ธ์ž๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. React๋Š” ์ด ํ•จ์ˆ˜๋ฅผ ๋‘ ๊ฐœ ์ธ์ž props์™€ ref๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ˜ธ์ถœํ•˜๊ณ , ์ด ํ•จ์ˆ˜๋Š” React ๋…ธ๋“œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

const FancyButton = React.forwardRef((props, ref) => (  <button ref={ref} className="FancyButton">    {props.children}
  </button>
));

// You can now get a ref directly to the DOM button:
const ref = React.createRef();
<FancyButton ref={ref}>Click me!</FancyButton>;

์œ„์˜ ์˜ˆ์‹œ์—์„œ React๋Š” <FancyButton ref={ref}> ์—˜๋ฆฌ๋จผํŠธ์— ์ฃผ์–ด์ง„ ref๋ฅผ React.forwardRef ํ˜ธ์ถœ์‹œ ๋ Œ๋”๋ง ํ•จ์ˆ˜์— 2๋ฒˆ์งธ ์ธ์ž๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ Œ๋”๋ง ํ•จ์ˆ˜๋Š” ref๋ฅผ <button ref={ref}> ์—˜๋ฆฌ๋จผํŠธ์— ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ React๊ฐ€ ํ•ด๋‹น ref๋ฅผ ๋ถ™์ด๊ณ  ๋‚œ ๋’ค, ref.current๋Š” <button> DOM ์—˜๋ฆฌ๋จผํŠธ ์ธ์Šคํ„ด์Šค๋ฅผ ์ง์ ‘ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ์ •๋ณด๋Š” ref ์ „๋‹ฌํ•˜๊ธฐ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

React.lazy

This content is out of date.

Read the new React documentation for lazy.

React.lazy()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋™์ ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ๋ฒˆ๋“ค์˜ ํฌ๊ธฐ๋ฅผ ์ค„์ด๊ณ , ์ดˆ๊ธฐ ๋ Œ๋”๋ง์—์„œ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ž‘์—…์„ ์ง€์—ฐ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ Code Splitting ๋ฌธ์„œ์—์„œ ์ตํž ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ์ž์„ธํžˆ ๋‹ค๋ฃฌ ์ด ๊ธ€์„ ์ฝ์–ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์Šต๋‹ˆ๋‹ค.

// ์ด ์ปดํฌ๋„ŒํŠธ๋Š” ๋™์ ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค
const SomeComponent = React.lazy(() => import('./SomeComponent'));

lazyํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๋ฉด ๋ Œ๋”๋ง ํŠธ๋ฆฌ ์ƒ์œ„์— <React.Suspense> ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ ์— ์œ ์˜ํ•˜์„ธ์š”. ์ด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋กœ๋”ฉ ์ง€์‹œ๊ธฐ(Loading indicator)๋ฅผ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

React.Suspense

This content is out of date.

Read the new React documentation for Suspense.

React.Suspense lets you specify the loading indicator in case some components in the tree below it are not yet ready to render. In the future we plan to let Suspense handle more scenarios such as data fetching. You can read about this in our roadmap.

React.Suspense๋Š” ํŠธ๋ฆฌ ํ•˜๋‹จ์— ์žˆ๋Š” ์ผ๋ถ€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์•„์ง ๋ Œ๋”๋งํ•  ์ค€๋น„๊ฐ€ ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๋กœ๋”ฉ ์ง€์‹œ๊ธฐ (Loading indicator)๋ฅผ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค. ํ–ฅํ›„์—๋Š” Suspense๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ(fetching)๋“ฑ์˜ ๋” ๋งŽ์€ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•  ๊ณ„ํš์ž…๋‹ˆ๋‹ค. ์ด์— ๋Œ€ํ•œ ๋‚ด์šฉ์€ ๋กœ๋“œ๋งต์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ˜„์žฌ <React.Suspense>๊ฐ€ ์ง€์›ํ•˜๋Š” ์œ ์ผํ•œ ์‚ฌ์šฉ ์‚ฌ๋ก€๋Š” lazy loading ์ปดํฌ๋„ŒํŠธ์ž…๋‹ˆ๋‹ค.

// ์ด ์ปดํฌ๋„ŒํŠธ๋Š” ๋™์ ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค
const OtherComponent = React.lazy(() => import('./OtherComponent'));

function MyComponent() {
  return (
    // Displays <Spinner> until OtherComponent loads
    <React.Suspense fallback={<Spinner />}>
      <div>
        <OtherComponent />
      </div>
    </React.Suspense>
  );
}

๊ด€๋ จ๋œ ๋‚ด์šฉ์„ Code Splitting ๊ฐ€์ด๋“œ ๋ฌธ์„œ์—์„œ ์„ค๋ช…ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. lazyํ•œ ์ปดํฌ๋„ŒํŠธ๋Š” Suspense ํŠธ๋ฆฌ ๋‚ด์˜ ๊นŠ์ˆ™ํ•œ ๊ณณ์— ์œ„์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์— ์œ ์˜ํ•˜์„ธ์š”. ์ฆ‰, Suspense๊ฐ€ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ์Œ€ ํ•„์š”๋Š” ์—†๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ฐ€์žฅ ์ข‹์€ ์‚ฌ์šฉ๋ฒ•์€ ๋กœ๋”ฉ ์ง€์‹œ๊ธฐ๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  ์‹ถ์€ ์ง€์ ์— <Suspense>๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด์ง€๋งŒ, Code Splitting์„ ํ•˜๊ณ ์ž ํ•˜๋Š” ์ง€์  ์–ด๋””์„œ๋“ ์ง€ lazy()๋ฅผ ์จ์•ผ ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ฃผ์˜

์‚ฌ์šฉ์ž์—๊ฒŒ ์ด๋ฏธ ํ‘œ์‹œ๋œ ์ฝ˜ํ…์ธ ์˜ ๊ฒฝ์šฐ, ๋‹ค์‹œ ๋กœ๋”ฉ ์ง€์‹œ๊ธฐ(Loading Indicator)๋กœ ์ „ํ™˜๋˜๋Š” ๊ฒƒ์€ ํ˜ผ๋ž€์„ ์•ผ๊ธฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋•Œ๋กœ๋Š” ์ƒˆ๋กœ์šด UI๊ฐ€ ์ค€๋น„๋˜๋Š” ๋™์•ˆ โ€œ๊ธฐ์กด์˜โ€ UI๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ์ด ๋” ๋‚˜์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด, ์ƒˆ๋กœ์šด transition API์ธ startTransition๊ณผ useTransition๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜์ •๋œ ๋‚ด์šฉ์„ transition์œผ๋กœ ํ‘œ์‹œํ•˜๊ณ  ์˜ˆ์ƒ์น˜ ๋ชปํ•œ fallback์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง์—์„œ์˜ React.Suspense

์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง ์ค‘์— Suspense ๊ฒฝ๊ณ„(Suspense Boundaries)๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ผ์‹œ ์ค‘๋‹จํ•˜์—ฌ ๋” ์ž‘์€ ๋ฉ์–ด๋ฆฌ๋กœ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง์ด ์ผ์‹œ ์ค‘๋‹จ๋˜๋ฉด ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด Suspense boundary์˜ fallback์„ ๋ Œ๋”๋งํ•˜๊ธฐ ์œ„ํ•ด ์šฐ์„  ์ˆœ์œ„๊ฐ€ ๋‚ฎ์€ ์ž‘์—…์„ ์˜ˆ์•ฝํ•ฉ๋‹ˆ๋‹ค. Fallback์„ ๋ Œ๋”๋ง ํ•˜๊ธฐ ์ „์— ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง์ด ์žฌ๊ฐœ๋œ๋‹ค๋ฉด(unsuspends) ์‹ค์ œ ์ฝ˜ํ…์ธ ๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  fallback์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

React.Suspense during hydration

Suspense boundaries depend on their parent boundaries being hydrated before they can hydrate, but they can hydrate independently from sibling boundaries. Events on a boundary before it is hydrated will cause the boundary to hydrate at a higher priority than neighboring boundaries. Read more

React.startTransition

This content is out of date.

Read the new React documentation for startTransition.

React.startTransition(callback)

React.startTransition ๋Š” ์ œ๊ณต๋œ ์ฝœ๋ฐฑ์˜ ๋‚ด๋ถ€๋ฅผ transition์œผ๋กœ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๊ฒŒํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋Š” React.useTransition ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ฃผ์˜

Transition ์—…๋ฐ์ดํŠธ๋Š” click๊ณผ ๊ฐ™์€ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’์€ ์—…๋ฐ์ดํŠธ์— ์ˆœ์„œ๋ฅผ ์–‘๋ณดํ•ฉ๋‹ˆ๋‹ค.

Transition ์ค‘ ์ผ์–ด๋‚˜๋Š” ์—…๋ฐ์ดํŠธ๋Š” ๋‹ค์‹œ ์ผ์‹œ ์ค‘๋‹จ๋œ(re-suspended) ์ฝ˜ํ…์ธ ์— ๋Œ€ํ•œ fallback์„ ํ‘œ์‹œํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, ์‚ฌ์šฉ์ž๊ฐ€ ์—…๋ฐ์ดํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๋™์•ˆ ๊ณ„์†ํ•˜์—ฌ ์ƒํ˜ธ ์ž‘์šฉ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค.

React.startTransition๋Š” isPending ํ”Œ๋ž˜๊ทธ๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. Transition์˜ ๋Œ€๊ธฐ ์ƒํƒœ(pending status)๋ฅผ ์ถ”์ ํ•˜๋ ค๋ฉด React.useTransition๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

Is this page useful?Edit this page