npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

isomorphic-css

v0.0.2

Published

Really simple method to gather your app's css. Useful for server side rendering.

Downloads

8

Readme

Isomorphic CSS

This is a styling framework agnostic way of gathering up all the css you use in your app. Useful if you're building static versions of your sites.

It uses a higher order component that adds a pushCss() method to each of your components.

Usage

Wrap your rendering method in The IsomorphicCss higher order component and pass it an array, this array will gather up strings of your css.

import IsomorphicCss from 'isomorphic-css'

//...
var cssArray = []
var appHtml = renderToString(<IsomorphicCss cssArray={cssArray}>
	<MyReallyAwesomeApp />
</IsomorphicCss>)
// Concatenate your css into one string
var appCss = cssArray.join('')

// You might use it to generate page markup
var myStaticPageHtml = `<!DOCTYPE html>
	<html>
	  <head>
			<style id="my-css">${appCss}</style>
	  </head>
	  <body>
	  	<div id="my-app">${appHtml}</div>
	  </body>
	</html>`
//...

To populate the css array you need to call pushCss inside your components.

Here's a simple example.

class App extends Component {

  static contextTypes = {
    pushCss: React.PropTypes.func,
  };

  componentWillMount = () => {
    this.context.pushCss(sheet.toString())
    // sheet.toString() is an example of jss code, but you can use whatever styling provider you like, pushCss just accepts a string of css.
  };

  //...
}

It doesn't matter if you call pushCss multiple times with the same css string duplicates will be ignored. This is useful when you're using components more than once.

That's it!

Troubleshooting

My client code throws a pushCss run time error, what gives ?!?

Unless you wrap your client code in the same <Isomporphic /> component the pushCss method won't be available in the context, this is effectively just providing a noop to avoid runtime errors. Alternatively you can do checks to see if your on the server before calling pushCss.