Action Logger addon for react-native storybook
npx @tessl/cli install tessl/npm-storybook--addon-ondevice-actions@9.1.0Storybook Actions Addon for React Native provides action logging capabilities within the Storybook development environment. It enables developers to monitor and log user interactions and events during component development, making it easier to debug and understand component behavior in isolation.
yarn add -D @storybook/addon-ondevice-actionsimport { register } from "@storybook/addon-ondevice-actions";
import ActionLogger from "@storybook/addon-ondevice-actions";For side-effect registration:
import "@storybook/addon-ondevice-actions/register";The package exports:
register: Function to register the addon with StorybookActionLogger: Default export - the container component for action loggingAdd the addon to your Storybook configuration:
// .rnstorybook/main.ts
import type { StorybookConfig } from '@storybook/react-native';
const main: StorybookConfig = {
addons: ['@storybook/addon-ondevice-actions'],
};
export default main;For custom registration scenarios:
import { register } from "@storybook/addon-ondevice-actions";
// Register the addon manually
register();For automatic registration using side-effects:
// This automatically calls register() when imported
import "@storybook/addon-ondevice-actions/register";The ActionLogger can also be used directly as a component:
import ActionLogger from "@storybook/addon-ondevice-actions";
import { ActionDisplay } from "storybook/actions";
const MyComponent = () => {
const [actions, setActions] = useState<ActionDisplay[]>([]);
const clearActions = () => setActions([]);
return (
<ActionLogger
active={true}
/>
);
};Once configured, the Actions addon automatically:
Registers the Actions addon with Storybook's addon system, adding the Actions panel for logging and displaying component interactions.
/**
* Registers the Actions addon with Storybook
* Adds the Actions panel to display logged interactions
*/
function register(): void;The register() function:
ADDON_ID)Container component that manages action state, event listening, and renders the action list UI.
/**
* Container component for managing action logging state and rendering
* @param active - Whether the panel is currently active/visible
*/
interface ActionLoggerProps {
active: boolean;
}
const ActionLogger: React.FC<ActionLoggerProps>;The ActionLogger container:
Presentation component that renders the action list with React Native styling.
/**
* Presentation component for displaying actions with native styling
* @param actions - Array of action displays to render
* @param onClear - Callback function to clear all actions
*/
interface ActionLoggerComponentProps {
actions: ActionDisplay[];
onClear: () => void;
}
export const ActionLogger: React.FC<ActionLoggerComponentProps>;Expandable component for inspecting complex action payloads with syntax highlighting.
/**
* Component for inspecting and expanding action values
* @param name - Optional name/key for the value
* @param value - The value to inspect and display
*/
interface InspectProps {
name?: string;
value: any;
}
const Inspect: React.FC<InspectProps>;The addon is built around several key components:
register): Main entry point that registers the addon with Storybook's addon system using addons.register() and addons.add()containers/ActionLogger): React component that manages action state with hooks, listens to Storybook events, and handles action deduplicationcomponents/ActionLogger): React Native component that renders the scrollable action list with native styling using ScrollView and Buttoncomponents/ActionLogger/Inspect): Expandable component with touch interaction for inspecting complex action payloads with syntax highlightingregister.js): Side-effect entry point that automatically calls the register functionaddons.getChannel()) to listen for EVENT_ID and SET_CURRENT_STORY eventsThe addon automatically handles:
fast-deep-equal comparison and counting with action.countSET_CURRENT_STORY event and optional action clearing based on clearOnStoryChange optionStyleSheet and native componentsTouchableOpacityaction.options.limit configuration/**
* Action display object containing action data and metadata
*/
interface ActionDisplay {
id: string;
count: number;
data: {
name: string;
args?: any[];
[key: string]: any;
};
options: {
clearOnStoryChange?: boolean;
limit: number;
};
}
/**
* Props for the ActionLogger container component
*/
interface ActionLoggerProps {
active: boolean;
}
/**
* Props for the ActionLogger presentation component
*/
interface ActionLoggerComponentProps {
actions: ActionDisplay[];
onClear: () => void;
}
/**
* Props for the Inspect component
*/
interface InspectProps {
name?: string;
value: any;
}The addon relies on:
storybook/internal/manager-api, storybook/internal/core-events)storybook/actions)The addon integrates seamlessly with the broader Storybook ecosystem and requires Storybook 9+ as a peer dependency.