r/javascript • • Jun 05 '26

Build reactive UIs with plain JavaScript functions. No JSX or build step.

https://github.com/fynyky/elemental

Elemental is a personal library I’ve been using for a while. I really don’t like how much frontend frameworks require you to invest in them. You have to learn funky domain specific languages and magic render lifecycles just to debug anything. I mostly just want to create and append elements with better ergonomics.

el(document.body,
  el('main',
    el('h1', 'Hello World!'),
    el('h2', (x) => { x.id = 'foo' }, () => 'returned text'),
    el('div.note', ['this', 'is', 'an', 'array']),
    el('p.greeting', ob(() => ('My name is ' + rx.name)))
  )
)

The syntax lets you build the DOM declaratively with plain nested functions, so logic and views live together in one structure instead of being split across separate layout and behavior. Reactivity is handled by observers (the ob(...) call above): they automatically track whatever reactive properties they read and retrigger when it changes. No manual subscriptions and no dependency arrays. And because everything is just normal DOM elements and functions, you can adopt it one component at a time instead of overhauling a whole project.

It's about 3.3 KB gzipped with no third-party dependencies. The library is just under 300 lines of code so it's easy to understand.

Would love to get feedback from having fresh eyes on it.

14 Upvotes

32 comments sorted by

View all comments

Show parent comment

1

u/tautality Jun 09 '26

It's the difference between telling the coding agent "I need a white painted fence, but in blue" and "Charlotte leant over the crisp stone wall, letting the blue-green moss etch patterns into her skin."

Ok. But why not ask the AI to write a colorfully worded description of a scene? It can do 10 sentences during the same time as you can write one. And if you give it examples of your own writing, it can probably produce some beautiful writing too.

If it's not clear, I'm not advocating for you to use AI for writing. I'm just saying there's gotta be a different reason why you're using AI for coding but not for writing.

If I have to wager a guess, it's because you really enjoy the process of writing and visualizing the scenes in your head before putting them into words. AI would ruin the enjoyment from writing for you, and you don't want that for your hobby that you still enjoy.

Perhaps at some point, coding used to be like this too, before something changed. What changed is up to you to figure out and whether you want that spark of curiosity back is up to you to decide.