Socket
Book a DemoInstallSign in
Socket

@cognite/storyhooks

Package Overview
Dependencies
Maintainers
45
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cognite/storyhooks

Storyhooks is a super tiny tool intended to make setup and mocking easier when writing stories in Storybook for React components.

latest
npmnpm
Version
1.0.8
Version published
Maintainers
45
Created
Source
Cognite logo

Storyhooks

Storyhooks is a super tiny tool intended to make setup and mocking easier when writing stories in Storybook for React components.

It is intended to emulate a beforeEach/afterEach workflow -- the didMount function is called when the child is being mounted, and the willUnmount function can be used to perform a teardown when the child is ready to be unmounted.

npm version

Getting started

yarn add @cognite/storyhooks

or

npm i @cognite/storyhooks

Example Usage

To make use of StoryHooks in individual stories, start by importing it at the top of the file containing them:

import StoryHooks from '@cognite/storyhooks';

Pass in components as children of the StoryHooks component. Multiple children are supported. Check out stories/index.stories.tsx for more examples.

<StoryHooks
  didMount={() => {
    // This is a great place to perform setup actions, such as mocking out API calls performed by the component
    sinon.stub(backend, 'fetchData').returns([{ id: 1, value: 'my data' }]);
  }}
  willUnmount={() => {
    // This is a great place to perform teardown actions, such as:
    sinon.restore();
  }}
>
  <MyAwesomeComponent />
  <AnotherAwesomeComponent />
</StoryHooks>

Contributing

Feel free to send us a PR.

By contributing you agree to abide by the Code of Conduct.

FAQs

Package last updated on 18 Jul 2019

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