Need update in example code about external stylesheet
See original GitHub issueIn example code about external stylesheet https://github.com/zeit/next.js/tree/master/examples/with-global-stylesheet , it still has dangerouslySetInnerHTML
. According to this styled-jsx
improvement` https://github.com/zeit/styled-jsx/pull/148, we can reference imported stylesheet now.
I tried to change code and it works.
export default () =>
<div>
- <style dangerouslySetInnerHTML={{ __html: stylesheet }} />
+ <style jsx global>{stylesheet}</style>
<p>ciao</p>
</div>
The dangerouslySetInnerHTML
does not look right and might trigger eslint error. If my understanding is right, I’ll submit a PR for this.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:18 (11 by maintainers)
Top Results From Across the Web
External Style Sheets - Quackit Tutorials
An external style sheet is a separate file where you can declare all the styles that you want to use on your website....
Read more >HTML and CSS – Inline Style, External Stylesheet, CSS Code ...
There are 3 different ways you can style your HTML: inline styles,; internal styles (also known as embedded CSS), and; external stylesheets. In ......
Read more >CSS Tutorial For Beginners 06 - External Style Sheets
Hiya ninjas and ninjarettes! In this CSS for Beginners lesson we're going to be looking at why external style sheets are awesome, ...
Read more >External Style Sheets in CSS: Definition & Examples - Study.com
External style sheets are separate files with a .css extension that are referenced in the main HTML document. Learn cascading order rules to ......
Read more >How to add CSS - W3Schools
Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section. Example. External...
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
Alright @mocheng it works indeed! Apparently a combo of
babel-plugin-wrap-in-js
and webpack’sraw-loader
does the trick. But I wouldn’t use it in production yet because the babel plugin doesn’t have tests and when doing server side rendering styled-jsx writes the css in astyle
tag in the page which means that it is never cached therefore if you have a lot of css and big external files your page size can grow considerably.Since there is a solution though we might explore ways to allow this in a performant way – maybe we should write external compiled files for SSR in actual
.css
files and then load them using a regularlink
tags rather than an inlinestyle
.for regular global styles files I would just serve them from
/static
and include them in the page with alink
tag. You can use aprebuild
script to copy or build them intostatic
.