Electrode Subapp for Preact and Redux Bundler

1.1.1 · maintenance · verified Tue Apr 21

This module, `subapp-pbundle`, version 1.1.1, serves as an integration layer for Electrode subapps utilizing the Preact UI framework and `redux-bundler` for state management. It essentially re-exports core functionalities from `subapp-web` and adapts them for Preact, including re-exporting Preact's `h`, `Component`, and `render` APIs for convenience. A key differentiator is its `reduxBundlerLoadSubApp` API, specifically designed for loading `redux-bundler`-based subapps within the Electrode ecosystem. The package is primarily distributed as ES modules, advocating for modern bundling practices like tree-shaking. While it provides server-side rendering (SSR) context support via `AppContext`, further support for advanced features like React Router and Preact Suspense remains "TBD," suggesting a slower release cadence or a maintenance-focused development cycle since its initial release around 2016 by WalmartLabs.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates defining an Electrode subapp with Preact, using `reduxBundlerLoadSubApp` and accessing SSR context via `AppContext`.

/** @jsx h */
import { h, reduxBundlerLoadSubApp, AppContext } from "subapp-pbundle";
import { useState } from 'preact/hooks'; // Assuming preact/hooks is also available

const MyPreactComponent = () => {
  const [count, setCount] = useState(0);
  return (
    <AppContext.Consumer>
      {({ isSsr, ssr, subApp }) => (
        <div>
          <h1>My Electrode Subapp</h1>
          <p>Current count: {count}</p>
          <button onClick={() => setCount(count + 1)}>Increment</button>
          <p>Running on SSR: {`${Boolean(isSsr)}`}</p>
          {isSsr && ssr && ssr.request && <p>Request URL: {ssr.request.url ?? 'N/A'}</p>}
          <p>Subapp name: {subApp?.name ?? 'Unknown'}</p>
        </div>
      )}
    </AppContext.Consumer>
  );
};

export default reduxBundlerLoadSubApp({ name: "MyComponent", Component: MyPreactComponent });

view raw JSON →