Company Logo
  • Industries

      Industries

    • Retail and Wholesale
    • Travel and Borders
    • Fintech and Banking
    • Textile and Fashion
    • Life Science and MedTech
    • Featured

      image
    • Mastering Prompt Engineering in 2025
    • Techniques, Trends & Real-World Examples

      image
    • Edge AI vs. Cloud AI: Choosing the Right Intelligence for the Right Moment
    • From lightning-fast insights at the device level to deep computation in the cloud, AI deployment is becoming more strategic than ever.

  • Capabilities

      Capabilities

    • Agentic AI
    • Product Engineering
    • Digital Transformation
    • Browser Extension
    • Devops
    • QA Test Engineering
    • Data Science
    • Featured

      image
    • Agentic AI for RAG and LLM: Autonomous Intelligence Meets Smarter Retrieval
    • Agentic AI is making retrieval more contextual, actions more purposeful, and outcomes more intelligent.

      image
    • Agentic AI in Manufacturing: Smarter Systems, Autonomous Decisions
    • As industries push toward hyper-efficiency, Agentic AI is emerging as a key differentiator—infusing intelligence, autonomy, and adaptability into the heart of manufacturing operations.

  • Resources

      Resources

    • Insights
    • Case Studies
    • AI Readiness Guide
    • Trending Insights

      image
    • Safeguarding the Future with AI TRiSM
    • Designing Intelligent Systems That Are Trustworthy, Secure, and Accountable

      image
    • Agentic AI in Manufacturing: Smarter Systems, Autonomous Decisions
    • As industries push toward hyper-efficiency, Agentic AI is emerging as a key differentiator—infusing intelligence, autonomy, and adaptability into the heart of manufacturing operations.

  • About

      About

    • About Coditude
    • Press Releases
    • Social Responsibility
    • Women Empowerment
    • Events

    • Coditude At RSAC 2024: Leading Tomorrow's Tech.
    • Generative AI Summit Austin 2025
    • Foundation Day 2025
    • Featured

      image
    • Coditude Turns 14!
    • Celebrating People, Purpose, and Progress

      image
    • Tree Plantation Drive From Saplings to Shade
    • Coditude CSR activity at Baner Hills, where we planted 100 trees, to protect our environment and create a greener sustainable future.

  • Careers

      Careers

    • Careers
    • Internship Program
    • Company Culture
    • Featured

      image
    • Mastering Prompt Engineering in 2025
    • Techniques, Trends & Real-World Examples

      image
    • GitHub Copilot and Cursor: Redefining the Developer Experience
    • AI-powered coding tools aren’t just assistants—they’re becoming creative collaborators in software development.

  • Contact
Coditude Logo
  • Industries
    • Retail
    • Travel and Borders
    • Fintech and Banking
    • Martech and Consumers
    • Life Science and MedTech
    • Featured

      Mastering Prompt Engineering in 2025

      Techniques, Trends & Real-World Examples

      Edge AI vs. Cloud AI: Choosing the Right Intelligence for the Right Moment

      From lightning-fast insights at the device level to deep computation in the cloud, AI deployment is becoming more strategic than ever.

  • Capabilities
    • Agentic AI
    • Product Engineering
    • Digital transformation
    • Browser extension
    • Devops
    • QA Test Engineering
    • Data Science
    • Featured

      Agentic AI for RAG and LLM: Autonomous Intelligence Meets Smarter Retrieval

      Agentic AI is making retrieval more contextual, actions more purposeful, and outcomes more intelligent.

      Agentic AI in Manufacturing: Smarter Systems, Autonomous Decisions

      As industries push toward hyper-efficiency, Agentic AI is emerging as a key differentiator—infusing intelligence, autonomy, and adaptability into the heart of manufacturing operations.

  • Resources
    • Insights
    • Case studies
    • AI Readiness Guide
    • Trending Insights

      Safeguarding the Future with AI TRiSM

      Designing Intelligent Systems That Are Trustworthy, Secure, and Accountable

      Agentic AI in Manufacturing: Smarter Systems, Autonomous Decisions

      As industries push toward hyper-efficiency, Agentic AI is emerging as a key differentiator—infusing intelligence, autonomy, and adaptability into the heart of manufacturing operations.

  • About
    • About Coditude
    • Press Releases
    • Social Responsibility
    • Women Empowerment
    • Events

      Coditude At RSAC 2024: Leading Tomorrow's Tech.

      Generative AI Summit Austin 2025

      Foundation Day 2025

    • Featured

      Coditude Turns 14!

      Celebrating People, Purpose, and Progress

      Tree Plantation Drive From Saplings to Shade

      Coditude CSR activity at Baner Hills, where we planted 100 trees, to protect our environment and create a greener sustainable future.

  • Careers
    • Careers
    • Internship Program
    • Company Culture
    • Featured

      Mastering Prompt Engineering in 2025

      Techniques, Trends & Real-World Examples

      GitHub Copilot and Cursor: Redefining the Developer Experience

      AI-powered coding tools aren’t just assistants—they’re becoming creative collaborators in software development.

  • Contact

Contact Info

  • 3rd Floor, Indeco Equinox, 1/1A/7, Baner Rd, next to Soft Tech Engineers, Baner, Pune, Maharashtra 411045
  • info@coditude.com
Breadcrumb Background
  • Insights

Simple Example of Storybook with React, With Knobs, With Redux Store

Let's Talk

React

Storybook

Redux Store

Frontend

Storybook Environment

Storybook environment looks like this

Step to get Storybook in React App :

Step 1 Create Create App

npx create-react-app (app name)

Step 2 Go inside App Folder

cd (app name)

Step 3 Install Storybook Package

npx -p @storybook/cli sb init

Or

npx -p @storybook/cli sb init --type react

Step 4 Run Storybook

npm run storybook

After installing Storybook package you can directly run it as by default package provides two stories

Storybook package creates a ".storybook" folder and it contains main.js which basically tells storybook which files are stories and also one folder named "stories" which contains all stories. It contains two sample stories.

//main.js
module.exports = {
  stories: ['../stories/**/*.stories.js'],
  addons: ['@storybook/addon-actions', '@storybook/addon-links'],
};

You need to understand the naming convention here. Your story file name should be something like this "(component name).stories.js" then and only then storybook will recognize it.

Default button.stories.js will look like this

//button.stories.js
import React from 'react';
import { action } from '@storybook/addon-actions';
import Button from './Button';
export default {
  component: Button,
  title: 'Button',
};
export const text = () => <Button onClick={action('clicked')}>Hello Button</Button>;
export const emoji = () => (
  <Button onClick={action('clicked')}>
    <span role="img" aria-label="so cool">
      😀 😎 👍 💯
    </span>
  </Button>
);

Step 5 First understand the above code and delete two default files from the stories folder. You are not going to need them

Step 6 Now create Simple component name for example Button.js

//Button.js
import React from "react";
const Button = (props) => {
  return <button> {props.buttonName}</button>;
};
export default Button;

Step 7 Create a story file. To create a story file you need to create a file [ Button.stories.js ] inside the stories folder and you need to import component you want to make the story of as shown below.

//Button.stories.js

import React from "react";
import Button from "../src/Button";

export default {
  title: "My Button",
  component: Button,
};

export const ClickMe = () => <Button buttonName="Click Me" />;
export const Save = () => <Button buttonName="Save" />;
export const Delete = () => <Button buttonName="Delete" />;

As shown above you can call component as many time as you want to and pass different props to it.

Make sure you are giving each export a different meaningful name and also a unique title in export default.

Step 8 Now run storybook from terminal

npm run storybook

And your storybook will look like this

Run Storybook from Terminal

That' it! All done simple and plain example of a storybook with react.

Now if you click on Save button then Button name will gate change to Save and same for Delete

See how you can try on different components and this time pass different CSS to component as props. In the storybook environment you can check their look and feel.

Now you know why you should use storybook in react app development.

STORYBOOK WITH KNOBS

The storybook concept doesn't stop here. Storybook has additional functionality called "Addons"

Which gives advance functionalities to storybook and one of them is "Knobs".

So as you have seen before that we pass props as data to stories in storybook but what if you wanna check dynamic data or want to edit props on running environment so for that we use Knobs.

Knobs gives us to modify props data on running stories.

We will go step by step for this one also so let's assume you got simple storybook app up and running

Step 1 install the knob package

yarn add @storybook/addon-knobs —dev

Or

npm i add @storybook/addon-knobs —dev

Step 2 Add Addon to your main.js file and your main.js will look like this.

//main.js

module.exports = {
  stories: ["../stories/**/*.stories.js"],
  addons: [
    "@storybook/addon-actions",
    "@storybook/addon-links",
    "@storybook/addon-knobs/register",
  ],
};

Step 3 Import-Package inside story file.

So now inside your already created story file [ Button.stories.js ] import the add-on package

import { withKnobs, text } from "@storybook/addon-knobs";

step 4 Add Decorators variable inside export default

export default {
  title: "My Button",
  decorators: [withKnobs],
};

Step 5 use the imported text from package inside button pass props as

{text("Label", "Click Me")}

After doing all the above steps your Button.stories.js will look like this

import React from "react";
import Button from "../src/Button";
import { withKnobs, text } from "@storybook/addon-knobs";

export default {
  title: "My Button",
  decorators: [withKnobs],
};

export const ClickMe = () => {
  return <Button buttonName={text("Label", "Click Me")} />;
};
export const Save = () => <Button buttonName="Save" />;
export const Delete = () => <Button buttonName="Delete" />;
Storybook With Knobs

And you will look get screen something like this

Now let me explain what we did above.

So we got "text" from the package and basically text property gives us an input text area on the storybook panel from where we can change the button name.

So basically I don't have to write two-three export for the same component now and so you can remove both save and Delete button export from story file

If you change the label text property to &quots;Save&quots; then it is going to reflect on the button above instantly.

Just like Text property knobs has many and most useful are as follow

1 text

you have already seen it in the example above

It has a pretty simple syntax.

But first don't forget to import

import { text } from '@storybook/addon-knobs';

For whatever place you want to change value just add

text( default Id, default value)

2 select

Select gives us a dropdown options on the storybook panel and from that, we can change the data on story

To use first import select

import { select } from '@storybook/addon-knobs';

All knobs have the same kind of syntax with little variation so for select syntax is

select( name Of select, Options, Default Value, GroupId )

//example
	
  export const Save = () => {
    const options = {
      Red: "red",
      Blue: "blue",
      Yellow: "yellow",
      Rainbow: ["red", "orange", "etc"],
      None: null,
    };
  
    return <button>{select("Button Name", options, "red", "Button-Id1")}</button>;
  };
Storybook Select

3 object

Object is very important because with the help of object you can pass the JSON data to story and so you can check the actual JSON data on stories

To use first import object

import { object } from '@storybook/addon-knobs';

Syntax of an object is much similar to select property

object(label, defaultValue, groupId);

//Example 

export const Delete = () => {
  const defaultValue = {
    backgroundColor: "red",
  };
  const value = object("style", defaultValue, "styleId-1");
  return <button style={value}> Click me</button>;
};
Storybook Object

You can try out others like array, color, number, boolean.

STORYBOOK WITH REDUX STORE

Now after using storybook at advance level. The question arises that can we get actual redux store data in the storybook? So we can test components with real data coming from different API's and sources.

Answer is Yes, we can get redux store data in a storybook. To get redux data we need to make a few changes to stories files and add some files

Before we proceed I am assuming that you know how redux store works and saga middleware because we are gonna use saga middleware to get data.

Steps To Get Redux store data in Storybook

1 Bootstrap File

you need to create a bootstrap.js file in src/ directory.

//bootstrap.js
import React from "react";
import { Provider } from "react-redux";
import { applyMiddleware, createStore } from "redux";
import rootReducers from "./reducers/index";
import createSagaMiddleware from "redux-saga";
import RootSaga from "./sagas";

//saga middleware
const sagaMiddleware = createSagaMiddleware();

//add any other middleware if you want in middleware array below
export default ({ middleware = [ sagaMiddleware] } = {}) => {
  const store = createStore(rootReducers, applyMiddleware(...middleware));
  sagaMiddleware.run(RootSaga);
return [
    store,
    renderFunction => <Provider store={store}>{renderFunction()}</Provider>
  ];
};
Storybook Create Bootstrap.js File

So in the above file, we are returning render function which basically puts any provided function inside <Provider> tag and gives store access to it

2 Now you just need to import the bootstrap file in the story file. As we are getting data from store and if your application components work with store data then you don't need multiple story files. You can just call every component inside a single file.

//all.stories.js
import React from "react";
import { storiesOf } from "@storybook/react";
import OrderDetails from "../src/core/OrderDetails";
import PlceOrder from "../src/core/PlaceOrder";
import Customers from "../src/core/Customers";
import Items from "../src/core/Items";
import bootstrap from "../src/bootstrap";

// bootstrap object contains store and render 
const [store, render] =   ();
store.dispatch({
  type: "LOAD_DATA"
});

storiesOf("Story With Store", module)
  .addDecorator(render)
  .add("OrderDetails", () => {
    return <OrderDetails />;
  })
  .add("PlceOrder", () => {
    return <PlceOrder />;
  })
  .add("Customers", () => {
    return <Customers />;
  })
  .add("Items", () => {
    return <Items />;
  });

So you can see we triggered the "LOAD_DATA" event from the store and so saga gets trigger. On trigger saga method stores data inside redux store. You can see it in below code

//saga/index.js
import { all, put, takeEvery, call } from "redux-saga/effects";

function* fetchData() {
 const API = "http://www.json-generator.com/api/json/get/cexsZAdSUO?indent=2";
  const response = yield call(fetch, API);
  const data = yield response.json();
 yield put({ type: "COPY_DATA_TO_STORE", payload: data });
}

function* watchLoader() {
 yield takeEvery("LOAD_DATA", fetchData);
}

export default function* rootSaga() {
  console.log("rootSaga");
  yield all([watchLoader()]);
}

And we passed the "render" object coming from bootstrap to .decorator(). In simple words we are telling stories to go through this decor before submitting it to the storybook environment.

Now you know pretty much about the storybook. Personally I use it for every project as it helps a lot.

Simple one more fact that changes made in the project reflects on the storybook environment
[ npm run storybook ] much master than on project start [ npm start ]

I hope you got everything you were looking for and have a nice day !!

Elevate UI With Coditude's Front-End Expertise

Elevate UI With Coditude's Front-End Expertise

Connect with Coditude

Chief Executive Officer

Hrishikesh Kale

Chief Executive Officer

Chief Executive OfficerLinkedin

30 mins FREE consultation

Popular Feeds

Crawling Websites Built with Modern UI Frameworks Like React
August 25, 2025
Crawling Websites Built with Modern UI Frameworks Like React
Scraping JavaScript-Rendered Web Pages with Python
August 18, 2025
Scraping JavaScript-Rendered Web Pages with Python
 Enhancing Chatbots with Advanced RAG Techniques
August 05, 2025
Enhancing Chatbots with Advanced RAG Techniques
Hello World Thunderbird Extension Tutorial
July 22, 2025
Hello World Thunderbird Extension Tutorial
Company Logo

We are an innovative and globally-minded IT firm dedicated to creating insights and data-driven tech solutions that accelerate growth and bring substantial changes.We are on a mission to leverage the power of leading-edge technology to turn ideas into tangible and profitable products.

Subscribe

Stay in the Loop - Get the latest insights straight to your inbox!

  • Contact
  • Privacy
  • FAQ
  • Terms
  • Linkedin
  • Instagram

Copyright © 2011 - 2025, All Right Reserved, Coditude Private Limited

Simple Example of Storybook

Hello my gorgeous friend on the internet. So here we are going to learn about Storybook with react. We will start by knowing what is storybook? and why you should be using it? and how it helps in development.

As you are here I hope you know the basics of React app development like how to create a simple react app and its basic structure.

The storybook tool is an open-source tool and you can create components in an isolated environment. Storybook is supported by React, Vue and Angular.

So let's start with the Storybook definition "storybook is nothing a but an environment where you test your components user interface and its behavior"

Storybook with react gives completely different environments from which you can easily check the user interface of your components.

Storybook contains many stories represent some component. Story component can be of any size like from simple button in different CSS to big presentation div with different data.

Here's the checklist of storybook with react:

Storybook enviroment

Storybook with knobs

Storybook with redux store