Skip to main content
An injection is a named value a plugin registers for other code to find. The value can be a React component or a function. Other code looks up injections by name, or filters them by optional metadata.

Registering an injection

From a service, call this.inject(...):
src/main/services/my-plugin.ts
The call returns an unregister function. Wrap it in this.setup(...) so it cleans up on hot reload.

Reading injections

useInjections({ kind }) returns the live list of injections whose meta.kind matches.

Rendering an injection

<View name="..."> looks up the injection and renders its value as a React component. args is passed to the component as a prop and is also available via useViewArgs() in any child.

Meta conventions

The framework does not read meta. Consumers do. The conventional keys are:

Registering from React

useRegisterInjection registers an injection while the calling component is mounted, and unregisters on unmount. Use it when the value can only be constructed inside React, for example a CodeMirror extension built from a hook’s state.

Injecting without a value

With no meta, the framework just imports the module. The module’s top-level code runs, but nothing is added to the registry.

Advice

Advice is a kind of injection that replaces or wraps a specific exported function or component anywhere in the app. It is registered with this.advise(...), which targets the export by its source file and export name.
The type field controls how the wrapper relates to the original:
  • replace substitutes the original entirely.
  • around runs in place of the original. It receives the next function in the chain as its first argument; call it (or don’t) to decide whether the original runs.
  • before runs first with the original arguments.
  • after runs last and receives the result followed by the original arguments. Returning a value other than undefined overrides the result.
this.advise(...) is sugar over this.inject(...) with meta.kind: "advice". For the full reference, including how the wrapper module should be written for each type, see Advice.

Hot reloading

Adding, removing, or editing a this.inject(...) call invalidates the renderer prelude and reloads the window. Edits inside the injection module itself hot-replace through Vite.