jayspod

  • 홈
  • 태그
  • 방명록

디자인패턴 1

[TIL] React Compound Components Pattern (design pettern)

컴파운드 컴포넌트 패턴 간단하게 말하면 내부 상태를 공유하는 컴포넌트 코드 import { useState, useContext, createContext } from 'react'; const ToggleContext = createContext(); const Toggle = ({ children }) => { const [on, setOn] = useState(false); const toggle = () => setOn(!on); return {children}; }; const On = ({ children }) => { const { on } = useContext(ToggleContext); return on ? children : null; }; const Off = ({ children ..

Programming 2023.09.14
이전
1
다음
더보기
  • 분류 전체보기 (70)
    • Programming (65)
    • Review (5)
      • Spend (1)
      • Movie (1)
      • Book (2)
      • Coffee (1)

최근글과 인기글

  • 최근글
  • 인기글

최근댓글

페이스북 트위터 플러그인

Archives

Calendar

«   2025/05   »
일 월 화 수 목 금 토
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

방문자수Total

  • Today :
  • Yesterday :

Copyright © Kakao Corp. All rights reserved.

티스토리툴바