When writing an application, it is of great importance to design and test the components of the application. Unfortunately, going through the components separately can be difficult, but with the help of Storybook we are able to test complex activities and make sure that the components we have written always work as expected.

 

What is Storybook?

Storybook is a tool for creating application interface components. It allows you to view components, view the different states of each component and test them. Storybook makes component creation faster and easier by isolating them. We are able to create entire user interfaces without having to move around the application, and it helps document components for reuse, and gives you the ability to test them visually to prevent errors. Storybook works great with the React library, but it also supports technologies such as Vue, Angular, Web Components, Ember, Svelte, Preact.

storybook

Are you looking for a contractor working with Storybook ?
logo

First steps

After installing Storybook, we can create our first story. A story is a function that describes how a component is rendered and stored in Component Story Format (CSF), with files ending in .stories.js or .stories.ts. The following code shows the creation of a story that will store a component with a button.

import React from 'react';
import { Button } from './Button';

export default {
  title: 'Button',
  component: Button,
};

export const Primary = () => <Button primary>Button</Button>;

 

The above Story can be improved with an additional concept "args", which allows you to dynamically change the arguments of the component, that is, we will be able to dynamically change e.g. our button's color, size, text.

import React from 'react';
import { Button } from './Button';

export default {
  title: 'Button',
  component: Button,
};

const Template = (args) => <Button {...args} />;

export const Primary = Template.bind({});
Primary.args = {
   primary: true,
   label: 'Button',
};

Our offer

Web development

Find out more

Mobile development

Find out more

E-commerce

Find out more

UX/UI Design

Find out more

Outsourcing

Find out more

Related articles

Show all articles