{"id":22729807,"url":"https://github.com/gc-victor/h-h","last_synced_at":"2026-05-01T14:34:18.165Z","repository":{"id":46974812,"uuid":"273212947","full_name":"gc-victor/h-h","owner":"gc-victor","description":"h-h is a micro-library (\u003c2.5 KB) for creating user interfaces","archived":false,"fork":false,"pushed_at":"2021-11-02T16:33:55.000Z","size":423,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T01:13:49.771Z","etag":null,"topics":["client-side-rendering","hyperscript","incremental-dom","jsx","server-side-rendering","spa","ssg","static-site-generator"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gc-victor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-18T10:50:17.000Z","updated_at":"2021-11-02T16:33:58.000Z","dependencies_parsed_at":"2022-08-28T10:20:16.197Z","dependency_job_id":null,"html_url":"https://github.com/gc-victor/h-h","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gc-victor/h-h","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fh-h","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fh-h/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fh-h/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fh-h/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gc-victor","download_url":"https://codeload.github.com/gc-victor/h-h/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fh-h/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32501403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-side-rendering","hyperscript","incremental-dom","jsx","server-side-rendering","spa","ssg","static-site-generator"],"created_at":"2024-12-10T18:11:51.192Z","updated_at":"2026-05-01T14:34:18.099Z","avatar_url":"https://github.com/gc-victor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# h-h\n\nh-h is a micro-library (\u003c2.5 KB) for creating user interfaces. It doesn't require compilation as it uses HyperScript as a template engine. Instead of using a Virtual DOM, it uses dom diff to update the DOM reducing the memory allocation and GC thrashing for incremental updates. Its hooks allow reactive updates and side effects with a small API. It can be used for Static Site Generation, Server-Side Rendering and Client-Side Rendering.\n\n## Key Features\n\n-   Micro-library \u003c2.5 KB\n-   Without dependencies\n-   No compilation needed\n-   HyperScript as a template engine\n-   No Virtual DOM, uses dom-diff to update the DOM\n-   Reactive updates and side effects\n-   Small API, not much to learn\n-   Static Site Generator, Server-Side Rendering and Client-Side Rendering\n-   Plus, a tiny router\n\n## Let's Play\n\nYou can start using it without bundlers or compilers.\n\n[Demo CodeSandbox](https://codesandbox.io/s/silly-frost-mp0pp).\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n    \u003chead\u003e\n        \u003cscript type=\"module\"\u003e\n            import {\n                app,\n                component,\n                h,\n            } from 'https://cdn.jsdelivr.net/gh/gc-victor/h-h/dist/esm/index.js';\n\n            const Counter = component(({ update }) =\u003e {\n                const [count, setCount] = update(0);\n\n                const add = (ev) =\u003e setCount(ev.target.value);\n                const increment = () =\u003e setCount(count() + 1);\n                const decrement = () =\u003e setCount(count() - 1);\n\n                return h('div', {}, [\n                    h('button', { onClick: increment }, ['+']),\n                    h('input', { key: 'input', type: 'number', onInput: add, value: count() }, []),\n                    h('button', { onClick: decrement }, ['-']),\n                ]);\n            })();\n\n            app(document.getElementById('app'), Counter());\n        \u003c/script\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003cmain id=\"app\"\u003e\u003c/main\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Installation\n\nYou can use pnpm, npm or yarn to install it.\n\n```console\nnpm install git+https://github.com/gc-victor/h-h.git#main\n```\n\nImport it in your application.\n\n```js\nimport { app, h, component } from 'h-h';\n```\n\nOr import it in a `\u003cscript\u003e` as a module.\n\n```html\n\u003cscript type=\"module\"\u003e\n    import { app, h, component } from 'https://cdn.jsdelivr.net/gh/gc-victor/h-h/dist/esm/index.js';\n\u003c/script\u003e\n```\n\n### Dependencies\n\nThe only dependency is [html-element](https://github.com/1N50MN14/html-element) for Server Side Rendering or Static Site Generation.\n\n```console\nnpm install html-element\n```\n\n```javascript\nimport 'html-element/global-shim';\n\n// Your code ...\n```\n\n## Template engine\n\nBy default, you can use HyperScript. It doesn't require bundlers or compilers.\n\n```javascript\nh('h1', { className: 'bold' }, ['h-h']);\n```\n\nA key attribute is required to keep the focus of an active element when its content change.\n\n```javascript\nh('input', { key: 'input', value: newValue() }, []);\n```\n\nTo transpile JSX you can use [esbuild](https://esbuild.github.io/content-types/#jsx) or [Babel plugin](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx) to convert it to JavaScript.\n\n```javascript\nimport { app } from 'h-h';\n\nconst App = component(() =\u003e {\n    return \u003ch1 className=\"bold\"\u003eh-h\u003c/h1\u003e;\n})();\n\napp(document.getElementById('app'), App());\n```\n\n## Component\n\nh-h components provide isolated states to work with it and offer a small API to make it easy to learn.\n\n### API\n\nThe injected hooks allow reactive updates and side effects for the components.\n\n```javascript\nconst App = component(({ cleanup, execute, props, update }) =\u003e {\n    const [state, setState] = update('');\n\n    execute(() =\u003e {\n        console.log('EXECUTED ONCE');\n    }, []);\n    execute(() =\u003e {\n        console.log('EXECUTED EACH TIME THE VARIABLE CHANGES');\n    }, [variable]);\n    cleanup(() =\u003e {\n        console.log('cleanup');\n    });\n\n    return h('h1', {}, ['h-h']);\n});\n```\n\n-   **cleanup**: is triggered when the component element is deleted from the DOM\n-   **execute**: is the main way to trigger side effects, you can use more than once in a single component\n-   **props**: are the properties used to send data from one component to another\n-   **update**: manages the component states, you can use more than once in a single component. It returns an array, where the first item is a function with the current state, and the second is the setter\n\n## App\n\nYou can create as many apps as you need.\n\n```javascript\napp(document.getElementById('app'), App());\n```\n\n## Router\n\nThe router has to be initialized as part of the configuration of our application.\n\n```javascript\nrouter({\n    '/': {\n        id: 'app', // by defaul the id is app\n        title: () =\u003e 'App 1',\n        view: () =\u003e h('div', {}, ['App 1']),\n    },\n    '/:slug': {\n        id: 'app2', // by defaul the id is app\n        title: () =\u003e 'App 2',\n        view: () =\u003e h('div', {}, ['App 2']),\n    },\n});\n```\n\nTo navigate through the application, you have to add the `to` method to an anchor.\n\n```javascript\nimport { to } from 'h-h/router';\n```\n\n```javascript\nh('a', { href: '/', onClick: to }, ['View 1']);\n```\n\n## Acknowledgments\n\n### Inspiration\n\n-   [React](https://reactjs.org/)\n-   [HyperScript](https://github.com/hyperhype/hyperscript)\n-   [HyperApp](https://github.com/jorgebucaran/hyperapp)\n-   [udomdiff](https://github.com/WebReflection/udomdiff)\n\n### Tools\n\n-   [esbuild](https://esbuild.github.io/)\n-   [gzip-size](https://esbuild.github.io/)\n-   [d-d](https://github.com/gc-victor/t-t)\n-   [esm](https://github.com/standard-things/esm) \n-   [es-module-shims](https://github.com/guybedford/es-module-shims)\n-   [html-element](https://github.com/1N50MN14/html-element) \n-   [jsdom](https://github.com/jsdom/jsdom)\n-   [t-t](https://github.com/gc-victor/t-t)\n-   [chokidar-cli](https://github.com/kimmobrunfeldt/chokidar-cli)\n\n## Compatible Versioning\n\n### Summary\n\nGiven a version number MAJOR.MINOR, increment the:\n\n-   MAJOR version when you make backwards-incompatible updates of any kind\n-   MINOR version when you make 100% backwards-compatible updates\n\nAdditional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR format.\n\n[![ComVer](https://img.shields.io/badge/ComVer-compliant-brightgreen.svg)](https://github.com/staltz/comver)\n\n## Contribute\n\nFirst off, thanks for taking the time to contribute!\nNow, take a moment to be sure your contributions make sense to everyone else.\n\n### Reporting Issues\n\nFound a problem? Want a new feature? First of all, see if your issue or idea has [already been reported](../../issues).\nIf it hasn't, just open a [new clear and descriptive issue](../../issues/new).\n\n### Commit message conventions\n\nA specification for adding human and machine readable meaning to commit messages.\n\n-   [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)\n\n### Submitting pull requests\n\nPull requests are the greatest contributions, so be sure they are focused in scope and do avoid unrelated commits.\n\n-   Fork it!\n-   Clone your fork: `git clone http://github.com/\u003cyour-username\u003e/h-h`\n-   Navigate to the newly cloned directory: `cd h-h`\n-   Create a new branch for the new feature: `git checkout -b my-new-feature`\n-   Install the tools necessary for development: `npm install`\n-   Make your changes.\n-   `npm run build` to verify your change doesn't increase output size.\n-   `npm test` to make sure your change doesn't break anything.\n-   Commit your changes: `git commit -am 'feat: add a feature'`\n-   Push to the branch: `git push origin my-new-feature`\n-   Submit a pull request with full remarks documenting your changes.\n\n## License\n\n[MIT License](https://github.com/gc-victor/h-h/blob/master/LICENSE)\n\nCopyright (c) 2021 Víctor García\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgc-victor%2Fh-h","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgc-victor%2Fh-h","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgc-victor%2Fh-h/lists"}