Skip to content

web-mjs/preact

Repository files navigation

ES Module (.mjs) for Web


use preact, hooks, custom-elements with
just import 'https://unpkg.com/@web-mjs/preact'

import { render, html, useState, useEffect } from 'https://unpkg.com/@web-mjs/preact';

const App = () => {
   const [clicks, setClicks] = useState(0);
   useEffect(() => {
     document.title = "Clicks: " + clicks;
   });

   return html`<button onClick=${() => setClicks((x) => x + 1)}>Click</button>`;
};

The module bundles preact, preact/hooks, html template and preact-custom-element. The full list of exported members:

  • h, html, render
  • createElement, cloneElement, isValidElement
  • Fragment, Component, createContext, hydrate, options
  • hooks: useReducer, useState, useEffect, useLayoutEffect, useRef, useCallback, useContext, useDebugValue, useErrorBoundary

Web Components

The registerCustomElement function from preact is exported as:

import { webComponents } from 'https://unpkg.com/@web-mjs/preact';

webComponents.register(SomeComponent, 'x-some-tag');

🚧 web-mjs is not affiliated with the Preact team. To build on your own, use rollup or npm run build

About

A .mjs bundle of preact, preact-hooks and preact-custom-element

Resources

License

Stars

Watchers

Forks

Packages

No packages published