
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
react-cssx
Advanced tools
Yet another way to apply CSS styles in JavaScript. It's not using an inline styling though. It's injecting a <style> tag.
import React from 'react';
import CSSX from 'react-cssx';
class Component extends React.Component {
render() {
return (
<CSSX styles={ this.css() }>
<h1>Title styled with <i>CSSX</i></h1>
</CSSX>
);
}
css() {
var color = '#BADA55';
return (
<style>
h1 {
color: {{ color }};
}
h1 i {
text-decoration: underline;
}
</style>
);
}
}
To make the code above works you'll need:
npm install react-cssx)<CSSX> component requires only one attribute - styles. It should be an array in the following format:
[
['h1', { 'font-size': '32px' }],
['h1 small', { 'font-size': '24px', 'font-weight': 'bold' }]
]
Of course writing CSS that way is not really nice. So let's use CSSX and replace it with:
css() {
return (
<style>
h1 {
font-size: 32px;
}
h1 small {
font-size: 24px;
font-weight: bold;
}
</style>
);
}
Notice that we should use a function that returns a <style> tag. If we create the <style> tag directly (in the render method for example) we'll get the CSS applied straight away to the whole page.
If you check some of the examples in a browser you'll see that the created styles are scoped to a specific element. For example:
class Component extends React.Component {
render() {
return (
<section>
<p>First paragraph</p>
<CSSX styles={ this.styleParagraph('#F00', 'second') }>
<p>Second paragraph</p>
</CSSX>
<CSSX styles={ this.styleParagraph('#00F', 'third') }>
<p>Third paragraph</p>
</CSSX>
</section>
);
}
styleParagraph(color, text) {
return (
<style>
p {
color: {{ color }};
}
p::before {
content: {{ text }};
}
</style>
);
}
}
There are three paragraphs rendered on the screen:

The first one does not have any local styles attached. However, the second and the third one are styled differently. They have their own dedicated CSS. CSSX library creates two <style> tags in the <head> of the document.

If this sounds interesting to you follow the links below:
FAQs
Proof of concept about using CSSX in React
The npm package react-cssx receives a total of 14 weekly downloads. As such, react-cssx popularity was classified as not popular.
We found that react-cssx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.