Socket
Socket
Sign inDemoInstall

@storybook/preview-api

Package Overview
Dependencies
48
Maintainers
26
Versions
534
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @storybook/preview-api


Version published
Weekly downloads
6.8M
decreased by-0.28%
Maintainers
26
Install size
6.32 MB
Created
Weekly downloads
 

Package description

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

Readme

Source

Preview API

TODO write proper documentation of this package

"Sub packages" README documents

This package used to be multiple packages (they have been combined into this one):

  • @storybook/addons read (old) docs
  • @storybook/core-client read (old) docs
  • @storybook/preview-web read (old) docs
  • @storybook/store read (old) docs

Keywords

FAQs

Last updated on 22 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc