Hyperapp

2.0.22 · active · verified Sun Apr 19

Hyperapp is an ultra-lightweight JavaScript framework for building single-page applications, emphasizing minimalism and performance. It integrates state management and a Virtual DOM engine, all within a small footprint (around 1 KB gzipped) and without external dependencies. The current stable version is 2.0.22, with major versions introducing significant feature enhancements and API refinements, though a strict release cadence isn't explicitly stated beyond regular updates. Its key differentiators include its small bundle size, a declarative and purely functional API, and a focus on minimizing the concepts developers need to learn, encompassing views, actions, effects, and subscriptions. It offers a streamlined approach to building performant web applications with an optimized diffing algorithm for efficient DOM updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a simple to-do list application using Hyperapp, including state management, event handling, and rendering with `h` and `text` functions.

import { h, text, app } from "hyperapp";

interface State {
  todos: string[];
  value: string;
}

const AddTodo = (state: State): State => ({
  ...state,
  value: "",
  todos: state.todos.concat(state.value),
});

const NewValue = (state: State, event: Event & { target: HTMLInputElement }): State => ({
  ...state,
  value: event.target.value,
});

// Ensure a root element exists in the DOM
const root = document.getElementById("app") || document.createElement("main");
if (!document.getElementById("app")) {
  root.id = "app";
  document.body.appendChild(root);
}

app<State>({
  init: { todos: [], value: "" },
  view: ({ todos, value }) =>
    h("main", {}, [
      h("h1", {}, text("To do list")),
      h("input", { type: "text", oninput: NewValue, value }),
      h(
        "ul",
        {},
        todos.map((todo) => h("li", {}, text(todo)))
      ),
      h("button", { onclick: AddTodo }, text("New!")),
    ]),
  node: root,
});

view raw JSON →