Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed withTheme #2033

Merged

Conversation

theboyWhoCriedWoolf
Copy link
Contributor

Updated withTheme to take default props from WrappedComponent. Fixes issues when ThemeProvider is not used but theme is defined in defaultProps.

@imbhargav5
Copy link
Member

Can we add a test case to this scenario? @theboyWhoCriedWoolf

@theboyWhoCriedWoolf
Copy link
Contributor Author

Tests added, I also changed the determineTheme method to prevent it from throwing an error and stay consistent with previous functionality of just throwing a warning if no theme is there.

Happy to make further changes if required.

Thanks

@@ -9,8 +9,8 @@ export default (props: Props, fallbackTheme: any, defaultProps: any) => {

/* eslint-disable react/prop-types */
const isDefaultTheme = defaultProps ? props.theme === defaultProps.theme : false;

const theme = props.theme && !isDefaultTheme ? props.theme : fallbackTheme || defaultProps.theme;
const defaultPropsTheme = (defaultProps || {}).theme;
Copy link
Contributor

@quantizor quantizor Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use EMPTY_OBJECT from utils/empties? And let's get rid of the extra variable allocation.

Copy link
Contributor

@quantizor quantizor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@quantizor quantizor merged commit adfb557 into styled-components:develop Oct 1, 2018
@mxstbr
Copy link
Member

mxstbr commented Oct 1, 2018

Thank you so much for helping us improve styled-components! Based on our Community Guidelines every person that has a PR of any kind merged is offered an invitation to the styled-components organization—that is you right now!

Should you accept, you'll get write access to the main repository. (and a fancy styled-components logo on your GitHub profile!) You'll be able to label and close issues, merge pull requests, create new branches, etc. We want you to help us out with those things, so don't be scared to do them! Make sure to read our contribution and community guidelines, which explains all of this in more detail. Of course, if you have any questions just let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants