カスタムReactボタンのclickイベントにlegitRipple.jsを追加します。 legitRipple JSへ リンク:ここhttps://matthias-vogt.github.io/legitRipple.js/Reactカスタムコンポーネント - ボタン - OnClickイベントでJQueryプラグインを呼び出します。
は私の案ですが、それが動作していない - 私は(.rippleするクリックイベントや参照をリンクする方法がわからない)イベント
Button = class Button extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
this.state = {
};
}
componentDidMount() {
//need to add JQuery function - on button click, I need to register an event? or somehow call (ref=buttonEl) $(buttonEl).ripple();
}
//do I need an componentWillUnmount as well?
onClick(ev) {
let onClickFn = this.props.onClick;
onClickFn && onClickFn(ev);
//somehow register an event to show the ripple?
}
render() {
return (
<div>
<button type="button" ref="buttonEl" className={this.props.className} onClick={this.onClick.bind(this)}>
{this.props.children}
</button>
</div>
);
}
}
ありがとうございました。私は、jQueryを呼び出すためにonClickイベントを待つ必要のないドキュメントを読んでいたはずです。 私はこれが問題ではないことを知っていますが、クリックイベントでjqueryプラグインを実行する必要があった場合は、どうすればよいでしょうか?私は将来この問題にぶつかるImを知っている。ほぼ同じように – hgill
。あなたのonClickでは、同じthis.refs.buttonElを使用して要素を取得して、普通の古いJSの中で何かjQueryを呼び出すことができます。また、コンストラクタでバインドしているので、onClick = {this.onClick} – Ryan