Context
컨텍스트 전파의 작동 방식
const ColorContext = createContext('black')
const ColorComponent = () => {
const color = useContext(ColorContext)
// 랜더링 횟수 확인
const renderCount = useRef(1)
useEffect(()=> {
renderCount.current += 1
})
return (
<div style={{ color}}>
Hello {color} (renders: {renderCount.current})
</div>
)
}컨텍스트를 사용한 모범 사례
Last updated