Last active
September 25, 2021 03:45
-
-
Save nleush/01fabc8d1287e64d68515b554be7057c to your computer and use it in GitHub Desktop.
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
// Include Iframely embed.js in your page using preferred method. E.g.: | |
// <script src="//cdn.iframe.ly/embed.js?api_key=[your key here]"></script> | |
// Add following methods to your component. | |
componentDidMount: function() { | |
// Builds widget after embed code rendered. | |
window.iframely && iframely.load(); | |
}, | |
getIframelyHtml: function() { | |
// Use embed code from API. | |
return {__html: this.iframelyEmbedHtmlCode}; | |
// Alternatively you can use widget generator without embed code from API. | |
// return {__html: '<a href="' + this.url + '" data-iframely-url>' + this.title + '</a>'}; | |
} | |
render: function () { | |
// Render raw widget html using 'dangerouslySetInnerHTML' attribute. | |
return <div dangerouslySetInnerHTML={this.getIframelyHtml()} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tlester - Here is a code snippet that is working with a functional component. Note I'm using Next.js so you'll need to inject the embed.js script another way if you're not using Next.js.