1
2
3
4
5
6
7
- /src
- App.js
- parent.js
- children.js
- other.js
- /context
- index.js
1
const MyThemeContext = React.createContext('light');
1
2
3
<MyThemeContext.Provider value='dark'>
{/* 특정 컴포넌트 */}
</MyThemeContext>
1
2
3
<MyThemeContext.Consumer>
{value => value === 'light' ? <p>기본 모드!<p> : <p>다크 모드!<p>}
</MyThemeContext.Consumer>
1
2
3
4
5
const MyThemeContext = React.createContext('light');
MyThemeContext.displayName = 'MyThemeDisplayName';
<MyThemeContext.Provider> // "MyThemeDisplayName.Provider" in DevTools
<MyThemeContext.Consumer> // "MyThemeDisplayName.Consumer" in DevTools
https://ko.reactjs.org/docs/context.html
https://velopert.com/3606
https://react.vlpt.us/basic/22-context-dispatch.html