I’m new to Storybook and am setting up my first React components and Stories file, as such:
Button.jsx:
import React from "react";
export default function Button({title}) {
return (
<div className="button">
{title}
</div>
)
}
Button.stories.js
import { Button } from './Button';
export default {
component: Button,
};
export const Primary = {
title: "Primary"
};
However, I am getting error
Unable to render story components-button--primary as the component annotation is missing from the default export
in Storybook.
I’m really not sure what this means and Google is not giving me anything.
Would anyone be able to point me in the right direction at all?
3
Answers
try exporting component like this
import React from "react";
function Button({title}) { }
export default Button
The error is showing because you are exporting a
default
component fromButton.jsx
but importing anamed component
from that same file inButton.stories.js
. Long story short, you are mixing your import and export strategies.To fix this, all you have to do is change your import.
Alternatively, you could opt to change the export instead.
You only need to do one of these.
And remember it is important to always
import
your components the same way youexport
theme. E.g.You can export/import named components like so:
You can export/import default components like so:
Hope this helps!
You are attempting to import the
"Button"
component in your "Button.stories.js" file, which is creating the problem. Because the component is exported as the default export, it should be imported without the need of curly brackets.