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

Update to new syntax #16

Closed
mxstbr opened this issue Dec 17, 2016 · 3 comments
Closed

Update to new syntax #16

mxstbr opened this issue Dec 17, 2016 · 3 comments

Comments

@mxstbr
Copy link
Member

mxstbr commented Dec 17, 2016

As of styled-components/styled-components#227 the new syntax for the private API is .withConfig:

const Box = styled.div.withConfig({ displayName: 'Box', componentId: 'Button_asdf123' })`
  styles: here;
`

This avoids issues on ReactNative where target would before need to be View (no string) and we'd need to import it, which would've made everything much more compilcated.

I'm thinking about switching this to be .__config to make sure people don't accidentally use it, but that's a trivial change. We should get this changed asap!

@vdanchenkov
Copy link
Member

How does it work with component wrapping? This way?

const StyledBox = styled(Box).withConfig({ displayName: 'StyledBox', componentId: 'Button_asdf123' })`
  styles: here;
`

@mxstbr
Copy link
Member Author

mxstbr commented Dec 18, 2016

To elaborate a bit on why this is a necessary change, on the web we can transpile our styled calls like so:

// before
const Box = styled.div``
// after
const Box = styled({ target: 'div' })``

Which is what we do right now! The issue is, that doesn't work on ReactNative. Imagine this:

// before
const Box = styled.View``

Transpiling it to this breaks, because in ReactNative there are no string primitives:

// after
const Box = styled({ target: 'View' })`` // 🚫 Breaks

Instead, we'd have to transpile it to this:

// after
import { View } from 'react-native'
const Box = styled({ target: View })``

Which would have been a pain to do!

So, with the new syntax we fully avoid this issue, because no matter what the user does this always works:

const Box = styled.div.withConfig({ })`` // That works perfectly fine
const Box = styled.View.withConfig({ })`` // That works too, no import needed!
const Box = styled(OtherComp).withConfig({ })`` // No problem
const Box = styled('div').withConfig({ })`` // No problem either

Does that explain better why we need to switch?

@vdanchenkov
Copy link
Member

@mxstbr Thanks for the explanation. I'll update it in a nearest time.

@mxstbr mxstbr closed this as completed in acc34ab Dec 20, 2016
mxstbr added a commit that referenced this issue Dec 20, 2016
Switch to new API withConfig, fixes #16
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

No branches or pull requests

2 participants