APIToGoAPIToGo
Visit APIToGo on LinkedIn
  • Documentation
  • Components
  • Themes
Quickstart
Configuration
Writing
Concepts
OpenAPI
Authentication
Integrations
Guides
Deployment
Extending
    Build ConfigurationVite ConfigSlotsCustom PluginsEvents
powered by apitogo
Extending

Events

APIToGo provides an events system that allows plugins to react to various application events. This system enables you to build dynamic features that respond to user interactions and application state changes.

Available Events

Currently, APIToGo supports the following events:

location

Code
type LocationEvent = (e: { from?: Location; to: Location }) => void;

Emitted when the user navigates to a different route. Provides both the previous (from) and current (to) Location objects from react-router.

Note that the from location will be undefined on the initial page load.

Consuming Events in Plugins

To consume events in your plugin, you can implement the events property in your plugin. This is useful for performing actions like sending analytics events or anything else that's not directly related to the UI.

Code
import { ZudokuPlugin, ZudokuEvents } from "@lukoweb/apitogo"; const navigationLoggerPlugin: ZudokuPlugin = { events: { location: ({ from, to }) => { if (!from) { console.log(`Initial navigation to: ${to.pathname}`); } else { console.log(`User navigated from: ${from.pathname} to: ${to.pathname}`); } }, }, };

Example in APIToGo Config

In your apitogo.config.ts, you can define the events like this:

Code
export default { plugins: [ { events: { location: ({ from, to }) => { if (!from) return; // E.g. send an analytics event sendAnalyticsEvent({ from: from.pathname, to: to.pathname, }); }, }, }, ], };

Using Events in Components

APIToGo provides a convenient useEvent hook to subscribe to events in your React components. The hook can be used in three different ways:

1. Getting the Latest Event Data

If you just want to access the latest event data without a callback:

Code
import { useEvent } from "@lukoweb/apitogo/hooks"; function MyComponent() { const locationEvent = useEvent("location"); return <div>Current path: {locationEvent?.to.pathname}</div>; }

2. Using Event Data in a Component

If you want to transform the event data, return a value from the callback:

Code
import { useEvent } from "@lukoweb/apitogo/hooks"; function MyComponent() { const pathname = useEvent("location", ({ to }) => to.pathname); return <div>Current path: {pathname}</div>; }

3. Using a Callback for Side Effects

If you just want to perform side effects when the event occurs:

Code
import { useEvent } from "@lukoweb/apitogo/hooks"; function MyComponent() { useEvent("location", ({ from, to }) => { if (from) { console.log(`Navigation: ${from.pathname} → ${to.pathname}`); } // No return value needed for side effects }); return <div>My Component</div>; }

The useEvent hook automatically handles subscription and cleanup in the React lifecycle, making it easy to work with events in your components.

Last modified on March 31, 2026
Custom Plugins
On this page
  • Available Events
    • location
  • Consuming Events in Plugins
    • Example in APIToGo Config
  • Using Events in Components
    • 1. Getting the Latest Event Data
    • 2. Using Event Data in a Component
    • 3. Using a Callback for Side Effects
TypeScript
TypeScript
TypeScript
TypeScript
TypeScript
TypeScript