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

Add innerRef support to withTheme HOC #710

Merged
merged 3 commits into from Apr 20, 2017
Merged

Add innerRef support to withTheme HOC #710

merged 3 commits into from Apr 20, 2017

Conversation

kitten
Copy link
Member

@kitten kitten commented Apr 19, 2017

No description provided.

@kitten kitten requested a review from geelen April 19, 2017 23:05
@kitten kitten added this to the v2.0 milestone Apr 19, 2017
innerRef={innerRef}
ref={ref}
/>
)
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I'd make that render method more like:

const { innerRef } = this.props
const refs = isStyledComponent(Component) ? { innerRef } : { ref: innerRef }

return (
  <Component {...{theme, ...this.props, ...refs}}/>
)

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to avoid the double-merge as a micro-optimisation, but it's definitely cleaner. Should I change it?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could also extract a variable, like _isStyledComponent and write:

<Component
  theme={theme}
  {...this.props}
  innerRef={_isStyledComponent ? innerRef : undefined}
  ref={_isStyledComponent ? undefined : innerRef}/>

@mxstbr-bot
Copy link

mxstbr-bot commented Apr 20, 2017

Warnings
⚠️ There are library changes, but not tests. That's OK as long as you're refactoring existing code

Generated by 🚫 dangerJS

@kitten kitten merged commit ccfcb77 into v2 Apr 20, 2017
@mxstbr mxstbr deleted the v2-withtheme-refs branch December 21, 2017 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants