Last active
February 20, 2018 06:37
-
-
Save lintonye/6a6d7fc7cf8d6603a0878a2327bf9407 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
import React, { PureComponent } from 'react'; | |
const IS_BROWSER = typeof window !== "undefined"; | |
export default class Form extends PureComponent { | |
componentWillMount() { | |
const { formId, version = 6 } = this.props; | |
if (IS_BROWSER) { | |
this.script = document.createElement("script"); | |
this.script.id = `_ck_${formId}`; | |
this.script.async = true; | |
this.script.src = `https://forms.convertkit.com/${formId}?v=${version}`; | |
} | |
} | |
componentDidMount() { | |
if (IS_BROWSER) { | |
// Make sure the convertKit inserts form elements again when the component is unmounted & re-mounted. | |
// This is useful to embed the form in for example a modal. Without this line, the sign up form will | |
// only appear the first time when the modal is open. | |
window._CK_processed = undefined; | |
this.div.appendChild(this.script); | |
} | |
} | |
saveDiv = div => (this.div = div); | |
render() { | |
return <div ref={this.saveDiv} />; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment