Skip to content

Instantly share code, notes, and snippets.

@StevanSlavnic
Forked from robbeman/HeadwayWidget.jsx
Created February 15, 2022 13:21
Show Gist options
  • Select an option

  • Save StevanSlavnic/d1693b7b610be26d20f743ba5bc24211 to your computer and use it in GitHub Desktop.

Select an option

Save StevanSlavnic/d1693b7b610be26d20f743ba5bc24211 to your computer and use it in GitHub Desktop.
Headway react component
/* global Headway */
import React, { memo } from 'react';
const HW_CONFIG_ACCOUNT = 'your-id-here'; // get this from env-variables
const ELEMENT_ID = 'headway-updates-widget';
function HeadwayWidget() {
// No need to render if no account is configured
if (!HW_CONFIG_ACCOUNT) {
return null;
}
// Use a function ref to determine if the DOM is ready for init
const initWidget = element => {
if (element) {
Headway.init({
selector: `#${ELEMENT_ID}`,
account: HW_CONFIG_ACCOUNT,
});
}
};
return <div id={ELEMENT_ID} ref={initWidget} />;
}
// prevent too much re-rendering with memo
export default memo(HeadwayWidget);
<!-- Put this somewhere in your document to load the widget script, make sure it is loade before react kicks in. -->
<script src="//cdn.headwayapp.co/widget.js" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment