👍:0
For one component to trigger a re-render of a sibling component, or a child of a sibling, they must trigger a re-render of some shared parent component. In this case it would make sense for all components to be children of a single root component since the theme should be consistent across the entire project, unless you have some specific use case.
Probably the easiest way to do this is to pass in a callback setTheme
as well as a theme
attribute from the topmost component. In the setTheme
callback, you should call the setState
of that topmost parent component, which will then trigger a re-rendering of every child component with the new theme.
Take a look here for a more detailed description of how to change the theme of react components.