Scoped css with pure css string
See original GitHub issueI tried to add scoped CSS plug-in to preact. But I have a problem. Can i get the component instance in “vnode hook” function?
import { options } from 'preact'
options.vnode = (vnode, component) =>{
//generate scoped attr by component
//add attr to vnode
}
Thanks! -dntzhang
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Scoped CSS / Sylvain Lesage - Observable
Use scoped() to wrap the HTML content and CSS styles. It creates a <div> wrapper with a unique class name ( scoped-dom-1671408000226-9578430986 ) ......
Read more >Saving the Day with Scoped CSS
One little known feature of HTML5 is Scoped CSS. It's an attribute for style blocks that may change the way we tackle certain...
Read more >scope - CSS: Cascading Style Sheets - MDN Web Docs
The :scope CSS pseudo-class represents elements that are a reference point for selectors to match against.
Read more >How to import css file as local scoped in ReactJS?
I want the home.css file to work only with the home.js view. Home.css .text1 { font-size: 1em ...
Read more >SFC CSS Features - Vue.js
Scoped styles do not eliminate the need for classes. Due to the way browsers render various CSS selectors, p { color: red }...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dntzhang technically there is a reference to the component instance associated with a given VNode, as a
._component
property (compressed in production as.__c
). However, VNodes are created long before they can be associated with a component, so this is not a reliable method of associating vnodes and components during theoptions.vnode
hook.The workaround is to store the component’s associated VNode, then reference it dynamically in your
options.vnode
hook:https://github.com/Tencent/omi/tree/master/packages/preact-css
Done. Many thanks to @developit and @marvinhagemeister .