Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does this library exist? #38

Open
eldoy opened this issue Dec 31, 2022 · 7 comments
Open

Why does this library exist? #38

eldoy opened this issue Dec 31, 2022 · 7 comments

Comments

@eldoy
Copy link

eldoy commented Dec 31, 2022

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

function myComponent(props) {
  return `<div>${props.name}</div>`
}
@Mike-Logit
Copy link

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.

@zuisong
Copy link

zuisong commented Jul 13, 2023

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.
}

@eldoy
Copy link
Author

eldoy commented Jul 15, 2023

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

@catdevnull
Copy link

it sanitizes text.

@jcubic
Copy link

jcubic commented Dec 30, 2023

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

@jcubic
Copy link

jcubic commented Mar 23, 2024

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

@devingfx
Copy link

devingfx commented Nov 6, 2024

You use JSX syntax and helpers that you can't use with template literals...
Like binding event handlers, or attributes as object.
This is a matter of choice, sugar vs vanilla...

You can not say that this library is useless! It permit to use JSX syntax but not along with p?react or any other Rube Goldberg machine...
JSX became used everywhere nowadays (some newbies front devs don't know that HTML in js is not a standard 😂)

Note this vhtml library can also be used with template literals along with htm that kindof brings some JSX shothands to template literals ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants