Instructions
Go to http://astexplorer.net/, select babylon6 as the parser, and babelv6 as the transform option.
Paste in the babel-plugin-react-string.js
code in the transform area.
Paste the following example source code:
function profile(props) {
return (
<div className="profile">
<img src={props.user.avatar || "default-avatar.png"} />
<h3>{[props.user.firstName, props.user.lastName].join(" ")}</h3>
<p>New messages: <strong>{props.messageCount}</strong></p>
</div>
);
}
It should be transformed to:
function profile(props) {
return (
[
"<div className=\"profile\"><img src=\"",
props.user.avatar || "default-avatar.png",
"\"><h3>",
[props.user.firstName, props.user.lastName].join(" "),
"</h3><p>New messages: <strong>",
props.messageCount,
"</strong></p></div>"
].join("")
);
}
If you add the following to the transformed code:
var html = profile({
user: {
firstName: "Bob",
lastName: "Smith",
avatar: "bob-smith.png"
},
messageCount: 42
});
console.log(html);
You should see as output:
<div className="profile"><img src="bob-smith.png"><h3>Bob Smith</h3><p>New messages: <strong>42</strong></p></div>