Why does this library exist?
Why does this library exist when you can just use template strings?
function myComponent(props) {
return `<div>${props.name}</div>`
}
I agree. It would be good to explain in the README if there are reasons I'm unaware of. I'm using typescript files to convert to individual javascript files for an MVC app with no React and wanted to use this plugin in my gulp/webpack setup, but then I thought to just use template strings instead.
For me, one reason is that template strings lack strong type.
For example:
function myComponent(props) {
return `<div>${props.name}</di>` // <-- Here is a spelling mistake, but it is not easily noticeable.
}
jsx
function myComponent(props) {
return <div>{props.name}</di> // <-- When using jsx , it will raise an error.
}
@zuisong Some kind of linter in your editor can tell you that, no need for JSX or Babel or any other garbage like that.
it sanitizes text.
You can have components and create really complex HTML with it. With template literal you only can create simple examples.
It's also great for debugging JSX libraries (if it would work correctly).