![]() |
VOOZH | about |
Storybook is an open-source UI development tool that facilitates the creation of reusable, well-documented components independently. It automates visual testing to prevent bugs and runs alongside the app in development mode. Additionally, it supports server-rendered component frameworks like Ruby on Rails.
Step 1: Create the react project folder
npm create-react-app projectstorybookStep 2: Change your directory to the newly created folder by using the following command.
cd projectstorybookStep 3: To add storybook in your project, in your terminal write the command
npm sb initProject Structure:
👁 ImageThe updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
}
Example: Let's create a component named WelcomeText that will show "Welcome to GeeksForGeeks" in two colors one is primary i,e green, and another one black named secondary. Let's create a folder named Components inside the folder create files such as WelcomeText.js,WelcomeText.css and WelcomeText.stories.js. and write the below-mentioned codes respectively.
Step to run the application: Open the terminal and type the following command.
npm run storybookOutput: