简体   繁体   English

Storybook React 及其示例组件不起作用

[英]Storybook React and their example component not working

I'm currently following this: https://storybook.js.org/basics/writing-stories/我目前正在关注这个: https : //storybook.js.org/basics/writing-stories/

And I created an example component button:我创建了一个示例组件按钮:

import React from 'react';

const Button = props => {
    return (
        <button>
           Hello
        </button>
    );
};

export default Button;

However, I'm not exactly sure what is going on under the hood in Storybook that this ends up creating the stories in the left navigation area, but the story examples that get rendered in my build are in fact my default Hello button.但是,我不确定 Storybook 的幕后发生了什么,这最终会在左侧导航区域中创建故事,但在我的构建中呈现的故事示例实际上是我的默认 Hello 按钮。

Are you mentioning, that when you fire up storybook, you just see your button with “hello” text and not any of the prop value that you are passing into it?你是不是提到,当你启动故事书时,你只会看到带有“hello”文本的按钮,而不是你传递给它的任何道具值?

If so, you must use the prop within the button definition as mentioned in the above answer.如果是这样,您必须在上面的答案中提到的按钮定义中使用道具。

If its some other issue, please provide more info on it.如果是其他问题,请提供有关它的更多信息。

First of all That's not how you use props.首先,这不是你使用道具的方式。

import React from 'react';

const Button = () => {
    return (
        <button>
           Hello
        </button>
    );
};

export default Button;

This will work.这将起作用。 And if you wanna use props do like this.如果你想使用道具,就这样做。

import React from 'react';

const Button = (props) => {
    return (
        <button>
           {this.props.yourPropName}     
        </button>
    );
};

export default Button;

this.props.yourPropName will show what you send using props. this.props.yourPropName将显示您使用道具发送的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM