-
-
Save sentiens/8ee9a7498b18a5bb5c57bd3aa211d768 to your computer and use it in GitHub Desktop.
@peerboard/core example
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 { 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