What is @storybook/api?
The @storybook/api package is a part of Storybook, which is an open-source tool for developing UI components in isolation for React, Vue, Angular, and more. It provides a set of APIs that allow developers to interact with Storybook's internal state and methods, enabling them to create custom addons and tools that can enhance the Storybook experience.
What are @storybook/api's main functionalities?
useStorybookApi
This hook allows you to access the Storybook API within your components or addons to interact with Storybook's state and functions, such as selecting a specific story.
import { useStorybookApi } from '@storybook/api';
const api = useStorybookApi();
api.selectStory('component-id');
useAddonState
This hook is used to persist state across the Storybook UI. It's useful for addons that need to maintain state.
import { useAddonState } from '@storybook/api';
const [state, setState] = useAddonState('your-addon-id', initialState);
useParameter
This hook allows you to retrieve the value of a parameter passed to a story, which can be used to customize the behavior of an addon.
import { useParameter } from '@storybook/api';
const parameter = useParameter('parameterName', defaultValue);
Other packages similar to @storybook/api
react-cosmos
React Cosmos is a development tool that allows you to build and test reusable React components. It is similar to Storybook in that it provides an isolated environment to develop components, but it does not offer the same addon API for extending its functionality.
docz
Docz is a documentation tool that leverages MDX to help you document your components. While it provides a way to showcase components similar to Storybook, it does not have an extensive API for creating addons or interacting with the tool's internal state.
7.0.0-alpha.0 (June 7, 2022)
Breaking Changes
- Build chain upgrades: TS4, Webpack5, modern ESM, TSUP (#18205)
- Create frameworks & rename renderers (#18201)
- Core-webpack: Factor out webpack dependencies (#18114)
- Core: Remove start-/build-storybook from all frameworks (#17899)
Features
- Core: Add pluggable indexers (#18355)
- CLI: Add dev/build commands (#17898)
- CLI: Add support for angular/cli v14 (#18334)
Bug Fixes
- Vue/Vue3: Fix decorators in StoryStoreV7 (#18375)
- Preview: Default select to
viewMode
story (#18370)
Maintenance
- Core: Split webpack presets out of frameworks (#18018)
- Core: Renderer refactor (#17982)
- Core: Allow builders to be set in presets (#18182)
- Core: Minimize webpack deps (#18024)
- Core: Make renderers presets (#18004)
- Examples: Simplify sb usage in package.json scripts (#18065)
For older versions of the changelog, see CHANGELOG.v6.md, CHANGELOG.v1-5.md