single-spa-preact is a helper library that helps implement single-spa registered application lifecycle functions (bootstrap, mount and unmount) for for use with Preact. Check out the single-spa-preact github.

Installation

  1. npm install --save preact

Quickstart

In your project’s entry file, add the following:

  1. import preact from 'preact';
  2. import rootComponent from './path-to-root-component.js';
  3. import singleSpaPreact from 'single-spa-preact';
  4. const preactLifecycles = singleSpaPreact({
  5. preact,
  6. rootComponent,
  7. domElementGetter: () => document.getElementById('main-content'),
  8. });
  9. export const bootstrap = preactLifecycles.bootstrap;
  10. export const mount = preactLifecycles.mount;
  11. export const unmount = preactLifecycles.unmount;

Options

All options are passed to single-spa-preact via the opts parameter when calling singleSpaPreact(opts). The following options are available:

  • preact: (required) The main Preact object, which is generally either exposed onto the window or is available via require('preact') or import preact from 'preact'.
  • rootComponent: (required) The top level preact component which will be rendered
  • domElementGetter: (required) A function that takes in no arguments and returns a DOMElement. This dom element is where the Preact application will be bootstrapped, mounted, and unmounted.