A minimal, educational React application demonstrating a plugin-based architecture using TypeScript, React Context, and dynamic imports. Perfect for learning how to build extensible frontend applications where features can be added or removed as independent plugins.
- Plugin contract: Each plugin is a self-contained React component with optional metadata.
- Dynamic loading: Plugins are loaded asynchronously at runtime using
import(). - Context-based registry: Plugins are shared across the app via React Context.
- Type-safe: Full TypeScript support with clear interfaces.
- Zero build-time coupling: Core app doesnβt need to know about plugins in advance.
src/
βββ plugins/ # Plugin implementations
β βββ GreetingPlugin.tsx
β βββ AnalyticsPlugin.tsx
βββ types/plugin.ts # Plugin interfaces
βββ PluginContext.tsx # React Context for plugins
βββ pluginLoader.ts # Dynamic plugin loader
βββ App.tsx # Main UI that renders plugins
βββ main.tsx # App entry point
git clone https://github.com/yalogica/react-plugin-lab.git
cd react-plugin-lab
npm installnpm run devOpen http://localhost:3000 to view the app.
npm run buildOutputs production-ready files to the dist/ folder.
-
Define a plugin as a default-exported React component with optional
meta:// src/plugins/MyPlugin.tsx export const meta = { id: 'my-plugin', name: 'My Plugin' }; export default function MyPlugin() { return <div>Hello from My Plugin!</div>; }
-
Register the plugin path in
pluginLoader.ts. -
The app dynamically imports all plugins on startup.
-
Plugins are rendered automatically in
App.tsxusing theusePlugins()hook.
- Create a new file in
src/plugins/, e.g.,WeatherPlugin.tsx. - Export a default React component and (optionally) a
metaobject. - Add its path to the
pluginPathsarray insrc/pluginLoader.ts. - Thatβs it! The plugin will appear on the dashboard.
This project illustrates key concepts:
- Dynamic imports (
import()) - React Context for global state
- TypeScript interfaces for contracts
- Decoupled, modular frontend architecture