tyom / storybook-addons

Useful add-ons for Storybook
https://tyom.github.io/storybook-addons/
MIT License
23 stars 2 forks source link

Introduce new addon storybook-react-context #8

Closed tyom closed 4 years ago

tyom commented 4 years ago

This addon gives access to context inside React component in Storybook story to the story closure. It's added to the context story amd can be accessed in the second argument of the story definition.

export const myStory = (_, { context: { state, dispatch } }) => {
  // story body
}
myStory.decorators = [withReactContext];

withReactContext can provide a custom reducer and context. By default state is assumed to be an object that is shallow assigned with new value set in dispatch.

withReactContext({
  context: React.createContext('')
  reducer: (state = '', action) ⇒ state + action;
})