Skip to content

Instantly share code, notes, and snippets.

@burtyish
Created August 18, 2015 11:40
Show Gist options
  • Save burtyish/3414b670563558581414 to your computer and use it in GitHub Desktop.
Save burtyish/3414b670563558581414 to your computer and use it in GitHub Desktop.
UserVoice Widget Trigger React Component
import React from 'react';
import _ from 'lodash';
const UserVoiceTrigger = React.createClass({
propTypes: {
id: React.PropTypes.string.isRequired
},
getDefaultProps() {
return {
id: _.uniqueId('uv_trigger_')
}
},
componentDidMount() {
if (UserVoice) {
UserVoice.push(['addTrigger', '#' + this.props.id]);
}
},
componentWillUnmount() {
if (UserVoice) {
UserVoice.push(['removeTrigger', '#' + this.props.id]);
}
},
render() {
return (
<span id={this.props.id}>
{this.props.children}
</span>
)
}
});
export default UserVoiceTrigger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment