Skip to content

Commit

Permalink
refactor: drop wrapper provider for components wrapped in withTheme (#44
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
satya164 authored and souhe committed May 22, 2019
1 parent ea6d1a6 commit 5fa3424
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/createWithTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,13 @@ const createWithTheme = <T: Object, S: $DeepShape<T>>(

return (
<ThemeContext.Consumer>
{theme => {
const merged = this._merge(theme, rest.theme);
const element = (
<Comp
{...rest}
theme={merged}
ref={_reactThemeProviderForwardedRef}
/>
);

if (rest.theme && merged !== rest.theme) {
// If a theme prop was passed, expose it to the children
return <ThemeProvider theme={merged}>{element}</ThemeProvider>;
}

return element;
}}
{theme => (
<Comp
{...rest}
theme={this._merge(theme, rest.theme)}
ref={_reactThemeProviderForwardedRef}
/>
)}
</ThemeContext.Consumer>
);
}
Expand Down

0 comments on commit 5fa3424

Please sign in to comment.