Skip to content

How to Change FluentProvider Theme from Child Component? #31311

Answered by khmakoto
tgram-3D asked this question in Q&A
Discussion options

You must be logged in to vote

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);
  
  ...
}

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@tgram-3D
Comment options

@khmakoto
Comment options

Answer selected by khmakoto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants