
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
jsx-to-string-2
Advanced tools
Parse your React JSX components to string
npm install jsx-to-string
import React from 'react';
import jsxToString from 'jsx-to-string';
// or var jsxToString = require('jsx-to-string');
let Basic = React.createClass({
render() {
return (
<div />
);
}
}); //this is your react component
console.log(jsxToString(<Basic test1="test" />)); //outputs: <Basic test1="test" />
...
. Use keyValueOverride
for custom key values.useFunctionCode (boolean)
Optional. Defaults to false. Whether or not to use the function actual source code instead of ...
For example:
import React from 'react';
import jsxToString from 'jsx-to-string';
//or var jsxToString = require('jsx-to-string');
let Basic = React.createClass({
render() {
return (
<div />
);
}
}); //this is your react component
let _onClickHandler = function () {
//no-op
}
console.log(jsxToString(<Basic onClick={_onClickHandler} />, {
useFunctionCode: true
})); //outputs: <Basic onClick={function _onClickHandler() { //no-op }} />
functionNameOnly (boolean)
Optional. Defaults to false. Whether prop function values should contain only the name.
This flag will only be used if useFunctionCode
is set to true.
For example:
import React from 'react';
import jsxToString from 'jsx-to-string';
//or var jsxToString = require('jsx-to-string');
let Basic = React.createClass({
render() {
return (
<div />
);
}
}); //this is your react component
let _onClickHandler = function () {
//no-op
}
console.log(jsxToString(<Basic onClick={_onClickHandler} />, {
functionNameOnly: true,
useFunctionCode: true
})); //outputs: <Basic onClick={_onClickHandler} />
keyValueOverride (object)
A key-value map that overrides the value of any React props with exact match with the given key. For example:
import React from 'react';
import jsxToString from 'jsx-to-string';
//or var jsxToString = require('jsx-to-string');
let Basic = React.createClass({
render() {
return (
<div />
);
}
}); //this is your react component
let _onClickHandler = function () {
//no-op
}
console.log(jsxToString(<Basic onClick={_onClickHandler} />, {
keyValueOverride: {
onClick: '_onClickHandler'
}
})); //outputs: <Basic onClick={_onClickHandler} />
ignoreProps (array)
An array of string keys that should be ignored from the JSX string. For example:
import React from 'react';
import jsxToString from 'jsx-to-string';
//or var jsxToString = require('jsx-to-string');
let Basic = React.createClass({
render() {
return (
<div />
);
}
}); //this is your react component
console.log(jsxToString(<Basic test1="ignore" />, {
ignoreProps: ['test1']
})); //outputs: <Basic />
displayName (string)
A custom value to be used as the component name. For example:
import React from 'react';
import jsxToString from 'jsx-to-string';
//or var jsxToString = require('jsx-to-string');
let Basic = React.createClass({
render() {
return (
<div />
);
}
}); //this is your react component
console.log(jsxToString(<Basic test1="ignore" />, {
displayName: 'CustomName'
})); //outputs: <CustomName />
FAQs
Parse your React JSX component to string
The npm package jsx-to-string-2 receives a total of 0 weekly downloads. As such, jsx-to-string-2 popularity was classified as not popular.
We found that jsx-to-string-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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.