dolog
Teact : ReactNode와 Context 본문
provider의 역할
- provider라는 단어 그대로 상태를 제공해주는 역할을 한다
context의 역할
- context는 컴포넌트 트리에서 특정 컴포넌트가 “어떤 상황”에서 필요한 정보를 제공받는 역할을 해줌
즉, 조명 컨트롤러에서 Provider는 Lamp와 LampController에게 각각 필요한 상태와 함수를 제공해주고 있음
createContext는 provider, consumer를 반환한다
(Legay)consumer는 무엇일까?
useContext를 쓰기 전 context를 제공받기 위한 방식이였음
컴포넌트 합성 -> 예를 들어 상태 하나만 props로 넘기지 말고, 컴포넌트 자체를 props로 넘겨버리기
참고
1. https://ko.legacy.reactjs.org/docs/context.html#before-you-use-context
2. https://ko.react.dev/reference/react/createContext#consumer
3. https://ko.legacy.reactjs.org/docs/context.html