
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
svg-reactify-2
Advanced tools
Transform SVG files into React elements.
As with most browserify transforms, you can configure it via the second argument to bundle.transform:
bundle.transform(require('svg-reactify'), { default: 'image' });
or inside your package.json configuration:
{
"browserify": {
"transform": [
["svg-reactify", { "default": "image" }]
]
}
}
Now you can do things like...
var React = require('react'),
SVG = {
Dog : require('images/dog.svg'),
Parrot: require('images/parrot.svg'),
Horse : require('images/horse.svg')
};
module.exports = React.createClass({
render: function () {
return (
<h2>Animals</h2>
<ul>
<li>
<SVG.Dog/>
</li>
<li>
<SVG.Parrot/>
</li>
<li>
<SVG.Horse/>
</li>
</ul>
);
}
});
svg-reactify uses templates to produce the react components. Currently there are two templates available - image and icon. Maybe there will be more in the future, like one for symbols for example.
Choose the default template using the default option. You can also set a regex for choosing templates based on filename like:
{
"browserify": {
"transform": [
["svg-reactify", { "default": "image", "icon": "\.icon" }]
]
}
}
This will use the image template by default and icon if the filename matches the regex \.icon. The other way around would be for example ["svg-reactify", { "default": "icon", "image": "\.image" }].
This template will produce a DOM tree looking like:
<span class="icon icon-__FILENAME_IN_KEBABCASE__">
<svg .... />
</span>
The <span> element will also inherit any props given to the element, for example the following react element:
<SVG.Dog className="customClass" something="else"/>
... will override the default class and produce:
<span class="customClass" something="else">
<svg .... />
</span>
You could then style the svg element further through CSS, for example:
.customClass > svg {
width: 100px;
height: 100px;
fill: #00ff00;
}
This template will produce a DOM tree containing only the SVG:
<svg .... />
It will NOT pass on any props given to the element, so you cannot set the className or such.
FAQs
transform SVG files into React elements
The npm package svg-reactify-2 receives a total of 0 weekly downloads. As such, svg-reactify-2 popularity was classified as not popular.
We found that svg-reactify-2 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.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.