Files
react.dev/examples/context/multiple-contexts.js
Alex Krolick 0d32f18b09 Kill highlight
2018-03-22 21:18:38 -07:00

36 lines
892 B
JavaScript

// Create a theme context, defaulting to light theme
const ThemeContext = React.createContext('light');
// Signed-in user context
const UserContext = React.createContext();
class App extends React.Component {
static propTypes = {
theme: PropTypes.string,
signedInUser: PropTypes.shape({
id: number,
name: string,
avatar: string,
}),
};
render() {
return (
<ThemeContext.Provider value={this.props.theme}>
<UserContext.Provider
value={this.props.signedInUser}>
<ThemeContext.Consumer>
{theme => (
<UserContext.Consumer>
{user => (
<ProfilePage user={user} theme={theme} />
)}
</UserContext.Consumer>
)}
</ThemeContext.Consumer>
</UserContext.Provider>
</ThemeContext.Provider>
);
}
}