React Pluggable

React Pluggable

  • Docs
  • FAQ
  • Github
  • Hire The Creators

›Core Concepts

Getting Started

  • Introduction
  • Installation
  • Motivation

Examples

  • Hello World
  • Renderer Example
  • Event Example
  • Typing Example
  • Todo App

Core Concepts

  • Dependencies
  • Typing
  • How to create a Plugin
  • Events

Api References

  • API Overview
  • Plugin
  • IPlugin
  • PluginStore
  • RendererPlugin

Tips and Tricks

  • Naming Convention

FAQ

  • FAQ's

How to create a Plugin

You can create a Typescript plugin class by implementing the IPlugin interface. If you are using Javascript you can simply create a class that has the methods defined in the IPlugin interface.

import React from "react";
import { IPlugin, PluginStore } from "react-pluggable";

class HelloPlugin implements IPlugin {

  pluginStore!: PluginStore;

  getPluginName(): string {
    return "Hello@1.2.3";
  }

  getDependencies(): string[] {
    return ["ClickMe@1.0.0"];
  }

  init(pluginStore: PluginStore): void {
    this.pluginStore = pluginStore;
  }

  activate(): void {
    this.pluginStore.addFunction("showAlert", () => {
      alert("Hello World");
    });
  }

  deactivate(): void {
    this.pluginStore.removeFunction("showAlert");
  }
}

export default HelloWorldPlugin;

Note: If we directly define the type of pluginStore variable as PluginStore class (i.e. public pluginStore: PluginStore; ) then it will throw an error because PluginStore class is not initialized in either constructor or class property declaration.

In this case, we can declare pluginStore in Plugin class as shown:

pluginStore! : PluginStore;

← TypingEvents →
React Pluggable
Docs
Getting StartedExamplesCore ConceptsAPI ReferencesFAQ
Community
TwitterStackoverflowDiscord
More
GitHubContribution Guidelines

Star
Built with ♥ at GeekyAnts
Copyright © 2020 React Pluggable.