镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Why does this library exist? #38

Open

Description

@eldoy

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

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

Activity

  1. Mike-Logit commented on Jun 21, 2023

    @Mike-Logit

    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.

  2. zuisong commented on Jul 13, 2023

    @zuisong

    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.
    }
  3. eldoy commented on Jul 15, 2023

    @eldoy
    Author

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

  4. catdevnull commented on Aug 3, 2023

    @catdevnull

    it sanitizes text.

  5. jcubic commented on Dec 30, 2023

    @jcubic

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

  6. jcubic commented on Mar 23, 2024

    @jcubic

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

  7. devingfx commented on Nov 6, 2024

    @devingfx

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions