-
This seems like a very basic question but I'm having trouble finding any documentation on this. If I want to have a button or something in a child component to switch themes, how do I do that? I figured the useFluent hook can be used to get the current provider instance but I don't know how to properly set the theme.
So if I want to change the theme to teamsDark or something without drilling props through Root, how do I do that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@tgram-3D were you able to find a solution to this problem? |
Beta Was this translation helpful? Give feedback.
-
I think you'd have to keep track of it in your own context const SetTopLevelThemeContext = React.createContext<React.Dispatch<React.SetStateAction<Partial<Theme>>>>(undefined);
const TopLevelComponent = (props) => {
const [theme, setTheme] = React.useState<Partial<Theme>>(teamsLightTheme);
return (
<FluentProvider theme={theme}>
<SetTopLevelThemeContext.Provider value={setTheme}>
<Root />
</SetTopLevelThemeContext.Provider>
</FluentProvider>
);
}
...
const AnotherInnerComponent = (props) => {
const setTopLevelTheme = React.useContext(SetTopLevelThemeContext);
setTopLevelTheme(anotherTheme);
...
} |
Beta Was this translation helpful? Give feedback.
I think you'd have to keep track of it in your own context