Skip to content

Instantly share code, notes, and snippets.

@dugjason
Created April 27, 2023 19:49
Show Gist options
  • Save dugjason/bc6562461f6535f435c4f71bef64fba7 to your computer and use it in GitHub Desktop.
Save dugjason/bc6562461f6535f435c4f71bef64fba7 to your computer and use it in GitHub Desktop.
Next.JS React component for Front Chat
// ./components/front-chat.tsx
"use client";
import Script from "next/script";
export function FrontChat() {
return (
<Script
id="front-chat-script"
src="https://chat-assets.frontapp.com/v1/chat.bundle.js"
onLoad={initFrontChat} /
></Script>
);
}
// Find your chatId in your Front Chat channel settings (in the JS snippet)
function initFrontChat() {
//@ts-expect-error
window.FrontChat("init", {
chatId: "YOUR_CHAT_ID",
useDefaultLauncher: true,
});
}
// ./layout.tsx
import "./globals.css";
import { FrontChat } from "@/components/front-chat";
export const metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
{/* The FrontChat component should be inserted before the closing </body> tag, after the main page content */}
<FrontChat />
</body>
</html>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment