Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@appsemble/preact

Package Overview
Dependencies
Maintainers
4
Versions
230
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appsemble/preact

Build your own blocks using Preact

  • 0.19.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
321
increased by101.89%
Maintainers
4
Weekly downloads
 
Created
Source

Appsemble Preact SDK

Build your own blocks using Preact

npm GitLab CI Code coverage Prettier

Installation

npm install @appsemble/preact preact

Usage

This package integrates Preact with @appsemble/sdk. Please read the documentation for a better understanding of how to use it.

bootstrap()

The bootstrap function takes a Preact component as an argument and renders. It takes the Appsemble block context as its props, extended with the ready() function. The ready() function needs to be called when the block is done rendering. Actions won’t be finalized for any blocks on the page, until all blocks are ready.

import { bootstrap } from '@appsemble/preact';
import { useEffect } from 'preact/hooks';

bootstrap(({ actions }) => {
  useEffect(() => {
    ready();
  }, []);

  return (
    <button onClick={() => actions.onClick()} type="button">
      Hello world!
    </button>
  );
});

Note: The script will be loaded only once. The component is then bootstrapped for every instance of your block type that is loaded by the app creator.

useBlock()

Get the block context. This is available for components that are rendered within a subtree of a component rendered by bootstrap

import { useBlock } from '@appsemble/preact';
import { VNode } from 'preact';

export function MyButton(): VNode {
  const { actions } = useBlock();

  return (
    <button onClick={() => actions.onClick()} type="button">
      Hello world!
    </button>
  );
}

<FormattedMessage />

This helper component renders a translated message ID.

import { FormattedMessage } from '@appsemble/preact';
import { VNode } from 'preact';

interface MyButtonProps {
  name: string;
}

export function MyButton({ name }: MyButtonProps): VNode {
  return (
    <button type="button">
      <FormattedMessage id="myButtonLabel" values={{ name }} />
    </button>
  );
}

License

LGPL-3.0-only © Appsemble

Keywords

FAQs

Package last updated on 20 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc