styled-jsx: Can't target root with a dynamic tag name
You can’t target a root element with a dynamic tag name, using className:
export default ({children, level = 2}) => {
const Heading = `h${level}`
return (
<Heading className='root'>
{children}
<style jsx>{`
.root {
color: red;
}
`}</style>
</Heading>
)
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 9
- Comments: 31 (12 by maintainers)
@arsen that’s on my radar, probably the next most important feature to add!
fixed in #462 will ship with styled-jsx v3
@simonsmith
jsx-123456is also applied to the outerdiv(.parent).To style the
Linkyou could temporarily use:global()until we find a better mousetrap:Any progress on this? 😃
@iamawebgeek this should work
@giuseppeg Yes I could. Some pointers on where to start would be apprichiated 😃
I think that it makes sense to automatically scope (add the className) in the case reported by the OP. In any other case we should scope only when the user adds a prop like
styled-jsxotherwise people can usecss.resolvei.e. prefer explicitness over magicWhen the styles are static it is better to define then outside of the
rendermethod otherwise they are treated as dynamic.