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

@dump247/storybook-state

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dump247/storybook-state

Manage component state in storybook stories.

  • 1.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3K
decreased by-7.58%
Maintainers
1
Weekly downloads
 
Created
Source

Storybook State

An extension for Storybook that manages the state of a stateless component. This makes it easier to write stories for stateless components.

Getting Started

Add @dump247/storybook

npm install --save-dev @dump247/storybook-state

Register the extension in addons.js.

import '@dump247/storybook-state/register';

Create a Story

Use the extension to create a story.

import React from 'react';
import { storiesOf } from '@storybook/react';
import { withState } from '@dump247/storybook-state';

storiesOf('Checkbox', module)
.add('with check', withState({ checked: false }, (store) => (
  <Checkbox {...store.state}
            label="Test Checkbox"
            onChange={(checked) => store.set({ checked })}/>
));

Extension

withState(initialState, storyFn)

initialState is the initial state of the component. This is an object where each key is a state value to set.

storyFn is the function that produces the story component. This function receives a Store object as the parameter.

Store API

store.state

Object that contains the current state.

store.set(state)

Set the given state keys. The state parameter is an object with the keys and values to set.

This only sets/overwrites the specific keys provided.

store.reset()

Reset the store to the initial state.

Panel

This project includes a storybook panel that displays the current state and allows for resetting the state.

Panel Screenshot

Keywords

FAQs

Package last updated on 24 Feb 2018

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