Context를 사용해 데이터를 깊게 전달하기
Props 전달하기의 문제점
Context: Props 전달하기의 대안
import Heading from './Heading.js';
import Section from './Section.js';
export default function Page() {
return (
<Section> // level = 1
<Heading level={1}>Title</Heading>
<Section> // 2
<Heading level={2}>Heading</Heading>
<Heading level={2}>Heading</Heading>
<Heading level={2}>Heading</Heading>
<Section> // 3
<Heading level={3}>Sub-heading</Heading>
<Heading level={3}>Sub-heading</Heading>
<Heading level={3}>Sub-heading</Heading>
</Section>
</Section>
</Section>
);
}
Context 실습하기
같은 컴포넌트에서 context를 사용하며 제공하기
Context로 중간 컴포넌트 지나치기
Context를 사용하기 전에 고려할 것
Context 사용 예시
Last updated