Home 🍊 2022-08-16
Post
Cancel

🍊 2022-08-16

πŸ”₯ 였늘 어디에 도전해보셨고, 무엇을 λ°°μš°μ…¨λ‚˜μš”?

🌊 ν•™μŠ΅ν•˜μ‹œλ©΄μ„œ κΆκΈˆν•˜μ‹  λΆ€λΆ„μ΄λ‚˜, μ–΄λ €μ› λ˜ 점은 λ­˜κΉŒμš”?

  • componentDidCatchμ—μ„œ setState둜 μƒνƒœλ₯Ό μ—…λ°μ΄νŠΈν•˜κ³  μ—λŸ¬ λ°œμƒ μ‹œ λŒ€μ²΄ UI λ Œλ”λ§μ„ μ œμ–΄ν•  수 μžˆμ§€λ§Œ 이런 방식은 μ΄ν›„μ˜ λ¦΄λ¦¬μ¦ˆμ—μ„œλŠ” μ‚¬μš©ν•  수 μ—†κ²Œ 될 κ²ƒμ΄λ―€λ‘œ static getDerivedStateFromError()λ₯Ό λŒ€μ‹  μ‚¬μš©ν•˜μ—¬μ•Ό ν•œλ‹€

    🐝 μ°Έκ³  μ—λŸ¬ 경계(Error Boundaries))


클래슀 μ»΄ν¬λ„ŒνŠΈ μ—λŸ¬ 경계(Error Boundaries)

  • πŸ”– μžλ°”μŠ€ν¬λ¦½νŠΈμ—μ„œ μ—λŸ¬ μ²˜λ¦¬λŠ” try-catchλ₯Ό μ‚¬μš©ν•˜λ©΄ λ˜λŠ”λ° λ¦¬μ•‘νŠΈμ˜ JSX λ¬Έλ²•μ—μ„œλŠ” μ‚¬μš©ν•  수 μ—†λ‹€.
  • πŸ”– μ—λŸ¬ κ²½κ³„λŠ” ν•˜μœ„ μ»΄ν¬λ„ŒνŠΈ 쀑 ν•˜λ‚˜κ°€ 였λ₯˜λ₯Ό λ§Œλ“€κ±°λ‚˜ 전달할 λ•Œ λ°œλ™ν•œλ‹€.
  • πŸ”– μ—λŸ¬λŠ” λ Œλ”λ§ 도쀑 생λͺ…μ£ΌκΈ° λ©”μ„œλ“œ 및 κ·Έ μ•„λž˜μ— μžˆλŠ” 전체 νŠΈλ¦¬μ—μ„œ μž‘μ•„λ‚Έλ‹€.
  • πŸ”– μ—λŸ¬ 경계λ₯Ό μ‚¬μš©ν•˜λŠ” μ΄μœ λŠ” μ—λŸ¬κ°€ λ°œμƒν•˜λ”λΌλ„ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ „μ²΄μ˜ μž‘λ™μ΄ μ€‘λ‹¨λ˜μ§€ μ•Šκ³  였λ₯˜λ₯Ό μ²˜λ¦¬ν•˜κΈ° μœ„ν•΄μ„œλ‹€.
  • πŸ”– ν•¨μˆ˜ν˜• μ»΄ν¬λ„ŒνŠΈμ—μ„œλŠ” 아직 μ‚¬μš©μ΄ λΆˆκ°€ν•˜μ—¬ 클래슀 μ»΄ν¬λ„ŒνŠΈλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      hasError: false,
    };
  }
  componentDidCatch(error) {
    this.setState({ hasError: true });
  }
  render() {
    return this.state.hasError ? (
      <p>Something went wrong.</p>
    ) : (
      this.props.children
    );
  }
}

export default ErrorBoundary;

🍊 JEJU.log

β›° λ‹¨μ‹œκ°„μ— 고강도 μš΄λ™μ„ μ›ν•œλ‹€λ©΄ μ„±μ‚°μΌμΆœλ΄‰ μ˜¬λΌκ°€κΈ°

μˆ™μ†Œμ—μ„œ μ„±μ‚°κΉŒμ§€ κ°€λŠ” 길이 λ„ˆλ¬΄ κ³ λ˜μ—ˆλ‹€. λ²„μŠ€λ₯Ό 두 λ²ˆμ΄λ‚˜ λ†“μ³μ„œ ν•œ μ‹œκ°„μ„ λ‚ λ Έκ³  μ„±μ‚° λ„μ°©κΉŒμ§€ ν•œμ‹œκ°„ 반 정도가 κ±Έλ Έλ‹€. λ„μ°©ν•΄μ„œ μ„±μ‚° μΌμΆœλ΄‰μ„ λ³΄λŠ”λ° 감탄이 λ‚˜μ˜€κΈ΄ ν–ˆλ‹€. μ‚¬μ§„μœΌλ‘œ λ³Έ 것보닀 크고 μ˜ˆλ»€λ‹€. μ •μƒκΉŒμ§€ μ˜¬λΌκ°€λŠ” 길은 생각보닀 νž˜λ“€κ±°λΌλŠ” μ‘°μ–ΈλŒ€λ‘œ μ§§μ§€λ§Œ κ°•ν•œ μ½”μŠ€μ˜€λ‹€. μ•„μ‰¬μš΄κ±΄ μ •μƒμ—μ„œ 찍은 사진은 싀물을 μ „ν˜€ 담지 λͺ»ν•œλ‹€γ… γ…  그건 눈으둜 λ΄μ•Όν•œλ‹€.

seongsan

πŸ–Ό κΈ°λŒ€λ³΄λ‹€ 훨씬 μ’‹μ•˜λ˜ λΉ›μ˜ 벙컀

deslumieres

This post is licensed under CC BY 4.0 by the author.

🍊 2022-08-11

🍊 2022-08-22