Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@storybook/preview-api

Package Overview
Dependencies
Maintainers
11
Versions
885
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/preview-api

  • 0.0.0-pr-29241-sha-95704996
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.9M
increased by13.33%
Maintainers
11
Weekly downloads
 
Created

What is @storybook/preview-api?

The @storybook/preview-api package is part of the Storybook ecosystem, which is a tool for developing UI components in isolation for React, Vue, Angular, and more. This package provides APIs to interact with the Storybook preview, allowing developers to control the rendering of stories, listen to events, and manipulate the state of the Storybook UI.

What are @storybook/preview-api's main functionalities?

Fetching and rendering stories

This feature allows developers to fetch story data by ID and render it using a custom component or utility.

import { useStorybookApi } from '@storybook/api';

function MyComponent() {
  const api = useStorybookApi();
  const story = api.getData('some-story-id');

  return <StoryRenderer story={story} />;
}

Listening to Storybook events

This feature enables components to listen to Storybook-specific events and react accordingly, as well as emit events to the Storybook environment.

import { useEffect } from 'react';
import { useChannel } from '@storybook/api';

function MyComponent() {
  const emit = useChannel({
    'storybook/my-event': (eventData) => {
      console.log('Event data:', eventData);
    }
  });

  useEffect(() => {
    emit('storybook/my-event', { payload: 'data' });
  }, [emit]);

  return <div>Check the console for event data.</div>;
}

Manipulating the Storybook UI

Developers can use this feature to programmatically control the Storybook UI, such as changing the current story displayed.

import { addons } from '@storybook/addons';

addons.setChannel(new Channel({ transport: new PostmsgTransport({ key: 'iframe-key' }) }));

addons.getChannel().emit('setCurrentStory', { storyId: 'some-story-id' });

Other packages similar to @storybook/preview-api

Keywords

FAQs

Package last updated on 16 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc