Created
April 4, 2019 15:00
-
-
Save arasmussen/7a964561ed5614892a2ab2372d664705 to your computer and use it in GitHub Desktop.
React example of the widget embed
This file contains 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
const CannySDK = { | |
init: () => { | |
(function(w, d, i, s) { | |
if (typeof w.Canny === 'function') { | |
return; | |
} | |
var c = function(){ | |
c.q.push(arguments); | |
}; | |
c.q = []; | |
w.Canny = c; | |
function l() { | |
if (d.getElementById(i)) { | |
return; | |
} | |
var f = d.getElementsByTagName(s)[0]; | |
var e = d.createElement(s); | |
e.type = 'text/javascript'; | |
e.async = true; | |
e.src = 'https://canny.io/sdk.js'; | |
f.parentNode.insertBefore(e, f); | |
} | |
if (d.readyState === 'complete') { | |
l(); | |
} else if (w.attachEvent) { | |
w.attachEvent('onload', l); | |
} else { | |
w.addEventListener('load', l, false); | |
} | |
})(window, document, 'canny-jssdk', 'script'); | |
}, | |
}; | |
export default CannySDK; |
This file contains 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, { Component, PropTypes } from 'react'; | |
import CannySDK from './CannySDK'; | |
const BoardToken = 'YOUR_BOARD_TOKEN'; | |
export default class Feedback extends Component { | |
static contextTypes = { | |
viewer: PropTypes.shape({ | |
ssoToken: PropTypes.string, | |
}), | |
}; | |
componentDidMount() { | |
CannySDK.init(); | |
const { viewer: { ssoToken } } = this.context; | |
Canny('render', { | |
boardToken: BoardToken, | |
basePath: '/feedback', | |
ssoToken: ssoToken, | |
}); | |
} | |
render() { | |
return ( | |
<div data-canny /> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment