News for hackers. Stuff that matters.
Re:Web Components Eliminate JavaScript Framework Lock-In by paulddraper on Monday November 27, 2023 @01:53PM (#38436507)
> its HTML as a string

Can you explain what you mean by that?

Re:Web Components Eliminate JavaScript Framework Lock-In by itslennysfault on Monday November 27, 2023 @01:58PM (#38436590)
This is the example from the article, and pretty common practice for web components. As far as an IDE is concerned this is just a string of text (it doesn't know/care that it is html). This makes it more error prone as the IDE can't catch syntax errors in the html.

  connectedCallback() {
    this.shadow.innerHTML = `
      <p>Hello from a web component!</p>
      <style>
        p {
          color: pink;
          font-weight: bold;
          padding: 1rem;
          border: 4px solid pink;
        }
      </style>
    `;
  }
Re:Web Components Eliminate JavaScript Framework Lock-In by paulddraper on Monday November 27, 2023 @02:05PM (#38436680)
Well, you can use `innerHTML` and a string, but you don't have to.

But there several alternatives:

1. Use DOM APIs (createElement).

2. Fetch the HTML as a separate resource.

3. Have the HTML in a separate file and bundle it with a bundler.

4. Use React/JSX.

5. Use a preferred templating library of your choice.

You can do whichever of these you like the most

Re:Web Components Eliminate JavaScript Framework Lock-In by thfuran on Monday November 27, 2023 @01:54PM (#38436537)
Html as a string literal in code rather than the html being in a separate .html file.
Re:Web Components Eliminate JavaScript Framework Lock-In by IshKebab on Monday November 27, 2023 @01:54PM (#38436526)
React uses JSX/TSX which is much better because it is syntax checked and even type checked in the case of TSX.