JSS meets JSX
JSSX is a small utility that makes it easier to use JSS within React components. More specifically it allows you to write this:
<button primary />
… instead of this:
<button className=classesprimary />
Dynamic Class Names
Without JSSX you would probably use a tool like classnames in order to dynamically assign classes:
<div className= />
With JSSX this boils down to:
<div btn primary active=active />
Usage
To use JSSX you need to add a @jsx
pragma to your code that instructs babel to use a custom factory instead of React.createElement
. This can be done like this:
;;; const sheet = jss; // create an element factory:const createElement = ; // tell babel use that factory:/* @jsx createElement */
Full Example
Here is a complete usage example:
;;;; const sheet = jss; const createElement = ; // tell babel to transpile JSX to createElement() calls:/* @jsx createElement */ { return <div> <a href=propslink active=propsactive>View</a> <button primary>Done</button> </div> ;} ReactDOM;
License
MIT