I am trying to use a Template to reuse code for making some stories. Here I have a Template called Template and want to create two stories called Default and Checked.
const Template = (args) => <Checkbox {...args} />;
export const Default = Template.bind({});
export const Checked = Template.bind({});
I know that we can have decorators and parameters on each of the stories
Default.decorators = [................]
Default.parameters = {................}
Checked.decorators = [................]
Checked.parameters = {................}
But if I had decorators and parameters on the template and then use bind for my Default and Checked stories, will the decorators and parameters applied on the template work on the Default and Checked stories?????
const Template = (args) => <Checkbox {...args} />;
Template.decorators = [.............];
Template.parameters = {.............};
export const Default = Template.bind({});
export const Checked = Template.bind({});
I also want to ask, how do I use hooks with my templates? I want to be able to do something like this, but it doesn't work sadly and crashes my storybook. I want the Default and Checked stories to use the variable checker and the setIsChecked hook.
const Template = (args) => {
const [checked, setIsChecked] = useState(true);
return (
<Checkbox {...args} />
);
};
export const Default = Template.bind({});
Default.args = {
checked: checker,
onClick: setIsChecked,
}
export const Checked = Template.bind({});
Checked.args = {
checked: checker,
OnClick: setIsChecked,
}
Thank you so much!