I have a React 16 app and would like to allow the user to change the theme for the entire app (including all Routes) by pressing a button.
So for example, I could have two themes in SCSS:
.theme-1 {
background-color: $bg-color-1;
color: $color-1;
}
.theme-2 {
background-color: $bg-color-2;
color: $color-2;
}
Then I would have a button as follows:
<Button onClick={ this.changeTheme() }
Can this be done? Specifically, I want to figure out these two parts:
- How to set the theme on all components that need to use the various
background-color
andcolor
. - The logic of the
changeTheme()
function. How exactly it would go about triggering a re-render on all affected components.
Thanks!