September 25th, 2024

Show HN: WebJSX – A tiny Web Components and JSX library

WebJSX is a minimal library for building web applications using Web Components and JSX, featuring createElement and applyDiff functions, supporting custom elements, and available for installation via npm.

Read original articleLink Icon
Show HN: WebJSX – A tiny Web Components and JSX library

WebJSX is a minimal library designed for building web applications using Web Components and JSX, emphasizing simplicity with two main functions: createElement and applyDiff. The library allows developers to write HTML markup using JSX, which returns Virtual Nodes, and efficiently merges these Virtual Nodes into the real DOM. As Web Components have matured, WebJSX aims to combine their capabilities with JSX/TSX for type safety, providing a modern approach to web development while adhering to web standards. The library supports event handling, fragments, and custom elements, making it versatile for various applications. Installation is straightforward via npm, and examples are available on StackBlitz for quick reference. Additionally, WebJSX is open-source under the MIT license, welcoming contributions and community support.

- WebJSX combines Web Components with JSX for modern web development.

- It features two core functions: createElement for JSX markup and applyDiff for DOM updates.

- The library supports custom elements, event handling, and fragments.

- Installation is simple via npm, with examples available on StackBlitz.

- WebJSX is open-source and encourages community contributions.

Link Icon 5 comments
By @tomhallett - 7 months
The statement I struggle with is "Web Components are mature now", not because of bugs per-se, but more of interoperability with the larger eco-system.

One example: if I want to use tailwindcss, then adopting web components comes at a cost/risk. While there are techniques like in this tutorial [1], you end up getting cut by the bleeding edge if you are not using Lit, you are using vite (based on comments), etc etc. (And the space moves so fast, I'd be afraid that any architectural differences between Tailwind and Web Components, might start to hurt me further in the future.)

1: https://www.youtube.com/watch?v=HwkXCYiRgtE

By @jeswin - 7 months
I wrote this because I felt that Web Components are ready to replace various React-like Component Frameworks out there. It was mostly written with gpt-o1. What was most impressive is the excellent test suite it produced.

I must have used around 50 prompts for this. The source code is here: https://github.com/webjsx/webjsx

This was the first prompt: https://chatgpt.com/share/66f0307c-e0f8-800d-873c-beb65abd7f...

By @mdhb - 7 months
Fun project and all but we already have good solutions for this written by teams of professionals with huge test cases and lots and lots of real world usage and you’re not going to prompt your way to something remotely of comparable quality as say Lit which already has the same kind of JSX functionality you’re looking for here, I’d even argue it’s better than JSX to be fair.
By @K0IN - 7 months
I am not that deep into react, but I always wondered, what exactly a vdom is and how the diffing works, the code is so easy to read and has a lot of comments which is really nice, thanks! I think I now understand react (or at least I hope so) a bit better.
By @breadwinner - 7 months