繁体   English   中英

将参数传递给React组件

[英]passing arguments into React components

我正在尝试通过以下内容:

 className={'follow-btn ${followClass}'} onClick={this.toggleFollow.bind(this)}

进入组件:

 <Button style="default" size="small" fill="fill">Follow</Button>

实际的组件代码:

<button className={classnames('button', this.props.classes, this.props.action, this.props.text, this.props.size, this.props.style, this.props.fill)}>{this.props.children}</button>

我无法弄清楚如何接受参数,因为它已进入组件,但似乎无法正常工作。 有任何想法吗?

谢谢

好的,所以我不确定是否会造成混淆,但是我将尝试通过一个例子进行说明。 据我了解,您想将一些CSS类名传递给React组件,如下所示:

class MyAwesomeButton extends React.Control {
    render() {
        var classes = classNames("button", this.props.customClasses);
        return (
            <button classNames={classes}>
                {this.props.text}
            </button>
        );
    }
}

然后像这样使用它:

<MyAwesomeButton customClasses="something something-else" text="Click Me!" />

希望我不要误会你。

暂无
暂无

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

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