import * as React from 'react'; import { useTheme, PartialTheme, Theme, ThemeContext, ThemeProvider } from '@fluentui/react/lib/Theme'; export default { title: 'ThemeProvider', }; const lightTheme: PartialTheme = { semanticColors: { bodyBackground: 'white', bodyText: 'black', }, }; const darkTheme: PartialTheme = { semanticColors: { bodyBackground: 'black', bodyText: 'white', }, }; export const ApplyThemeToBody = () => { const [isLight, setIsLight] = React.useState(true); return (
I am {isLight ? 'light theme' : 'dark theme'}
I am a nested {isLight ? 'dark theme' : 'light theme'}
); }; const ThemedContentFC = () => { const theme = useTheme(); console.log('theme from useTheme', theme); return null; }; class ThemedContent extends React.Component<{}> { public render() { return ( {(theme: Theme | undefined) => { console.log('theme from context consumer', theme); return null; }} ); } } export const AccessTheme = () => (
See console log
);