mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 20:53:08 +00:00
* Added an example showing how to update the context from inside a (deeply) nested component * Wrap comments * Wrap comments * Tweak wording * Prettier * Prettier * Typo: "funtion" -> "function"
21 lines
518 B
JavaScript
21 lines
518 B
JavaScript
import {ThemeContext} from './theme-context';
|
|
|
|
function ThemeTogglerButton() {
|
|
// highlight-range{1-2,5}
|
|
// The Theme Toggler Button receives not only the theme
|
|
// but also a toggleTheme function from the context
|
|
return (
|
|
<ThemeContext.Consumer>
|
|
{({theme, toggleTheme}) => (
|
|
<button
|
|
onClick={toggleTheme}
|
|
style={{backgroundColor: theme.background}}>
|
|
Toggle Theme
|
|
</button>
|
|
)}
|
|
</ThemeContext.Consumer>
|
|
);
|
|
}
|
|
|
|
export default ThemeTogglerButton;
|