Skip to content

Instantly share code, notes, and snippets.

@javarouka
Last active June 2, 2017 13:27
Show Gist options
  • Save javarouka/1ecea1df78d5cf26839023bcca98bc55 to your computer and use it in GitHub Desktop.
Save javarouka/1ecea1df78d5cf26839023bcca98bc55 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
function applyClipboard(element, selector) {
// implements ...
}
/**
* @Usage
* class SomeComponent extends Component {}
* export default clipboard('[clip-target]')(SomeComponent)
*/
export default function clipboard(selector) {
return (Component) => {
return class ClipboardDecorated extends Component {
componentDidMount() {
applyClipboard(ReactDOM.findDOMNode(this), selector);
}
componentDidUpdate() {
applyClipboard(ReactDOM.findDOMNode(this), selector);
}
render() {
return (
<Component {...this.props} />
);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment