Created
August 18, 2015 11:40
-
-
Save burtyish/3414b670563558581414 to your computer and use it in GitHub Desktop.
UserVoice Widget Trigger React Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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