Consuming Selected Theme
BlueBase exports a ThemeConsumer component to utilise current theme. This is a render prop component, which means it takes a function as a child. The function gets an object in the param with the following interface:
interface ThemeContextData {
// Helper method to change current theme.
changeTheme: (slug: string) => void,
// Current theme
theme: Theme
}Usage
The following snippet illustrates how to use a ThemeConsumerย component.
const ThemedComponent = () => (
<ThemeConsumer>
{
({ theme, changeTheme }: ThemeContextData) => {
// Use theme context here..
}
}
</ThemeConsumer>
);Example: ThemePicker
The following example shows how to use ThemeConsumer component to create a theme picker. This renders a picker component with a list of all installed themes. It not only uses the current theme to style itself, but also utilises the changeThemeย method to switch themes.
Last updated