Socket
Socket
Sign inDemoInstall

@storybook/preview-api

Package Overview
Dependencies
14
Maintainers
31
Versions
586
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @storybook/preview-api


Version published
Weekly downloads
7.7M
increased by1.21%
Maintainers
31
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/client-api 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 13 Nov 2023

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