Skip to content

Commit 5fa3424

Browse files
satya164souhe
authored andcommitted
refactor: drop wrapper provider for components wrapped in withTheme (#44)
BREAKING CHANGE: Previously if the theme differed from the one in context, we wrapped the component in a provider as well. However, most components don't need it and it can be confusing when trying to override the theme for only specific component. This commit drops this extra wrapper. The old behaviour can still be achieved by explicitly using a `ThemeProvider` instead of a `theme` prop.
1 parent ea6d1a6 commit 5fa3424

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/createWithTheme.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,13 @@ const createWithTheme = <T: Object, S: $DeepShape<T>>(
4141

4242
return (
4343
<ThemeContext.Consumer>
44-
{theme => {
45-
const merged = this._merge(theme, rest.theme);
46-
const element = (
47-
<Comp
48-
{...rest}
49-
theme={merged}
50-
ref={_reactThemeProviderForwardedRef}
51-
/>
52-
);
53-
54-
if (rest.theme && merged !== rest.theme) {
55-
// If a theme prop was passed, expose it to the children
56-
return <ThemeProvider theme={merged}>{element}</ThemeProvider>;
57-
}
58-
59-
return element;
60-
}}
44+
{theme => (
45+
<Comp
46+
{...rest}
47+
theme={this._merge(theme, rest.theme)}
48+
ref={_reactThemeProviderForwardedRef}
49+
/>
50+
)}
6151
</ThemeContext.Consumer>
6252
);
6353
}

0 commit comments

Comments
 (0)