Skip to content

Instantly share code, notes, and snippets.

@sentiens
Last active December 22, 2022 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sentiens/8ee9a7498b18a5bb5c57bd3aa211d768 to your computer and use it in GitHub Desktop.
Save sentiens/8ee9a7498b18a5bb5c57bd3aa211d768 to your computer and use it in GitHub Desktop.
@peerboard/core example
import { createForum } from "@peerboard/core";
// Settings -> Hosting -> Path prefix
const prefix = "/community";
// Settings -> Hosting -> Board ID
const communityID = BOARD_ID_FROM_SETTINGS;
// On the page you should have a <div id="community"></div> as a placeholder
const containerEl = document.getElementById('community');
const options = {
prefix,
// Recommended setting so that the community component
// will always occupy all available space
// replace HEADER_HEIGHT and FOOTER_HEIGHT with your values
// Check that window is defined for SSR cases
minHeight: typeof window !== 'undefined' ? window.innerHeight - HEADER_HEIGHT - FOOTER_HEIGHT : undefined,
// Update your page title according to the community state
onTitleChanged: title =>
window.document.title = "Your app community: " + title,
};
const promise = createForum(communityID, containerEl, options);
promise.then(() => {
// Here you can safely any loading indicators
}).catch(err => {
// Show error to the user
});
// We're suggesting to do cleanup everything the page dynamically, for example, on component unmount in React
// We support calling createForum in SSR is safe, in that case null will be returned, so you need to check that
const api = await promise.catch(err => console.error(err));
if (api) {
api.destroy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment