vhtml icon indicating copy to clipboard operation
vhtml copied to clipboard

Why does this library exist?

Open eldoy opened this issue 3 years ago • 7 comments

Why does this library exist when you can just use template strings?

function myComponent(props) {
  return `<div>${props.name}</div>`
}

eldoy avatar Dec 31 '22 21:12 eldoy

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.

Mike-Logit avatar Jun 21 '23 15:06 Mike-Logit

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 avatar Jul 13 '23 08:07 zuisong

@zuisong Some kind of linter in your editor can tell you that, no need for JSX or Babel or any other garbage like that.

eldoy avatar Jul 15 '23 02:07 eldoy

it sanitizes text.

catdevnull avatar Aug 03 '23 01:08 catdevnull

You can have components and create really complex HTML with it. With template literal you only can create simple examples.

jcubic avatar Dec 30 '23 20:12 jcubic

It's also great for debugging JSX libraries (if it would work correctly).

jcubic avatar Mar 23 '24 18:03 jcubic