febc11-react

6장 Context API

Context API란?

상태 끌어올리기

[그림 1. 상태 끌어올리기]

[그림 2. Context API]

prop drilling

[그림 3. props]

[그림 4. Context API]

사용 방법

Context 객체 생성

Provider 컴포넌트 작성

자식 컴포넌트에 Context 제공

import { CounterProvider } from '@context/CounterContext';
<CounterProvider>
  <Left1 />
  <Right1 />
</CounterProvider>

자식 컴포넌트에서 Context 사용

Context 남용 주의

Context API 사용 사례

Context API의 단점