React app example
Quick installation guide to setup the BetterBugs Web SDK widget for your React applications.
How to install BetterBugs Web SDK in React apps
3
Initialize the SDK (with default UI)
import { useEffect, useRef } from "react";
function App() {
// Initialization Code
const bbInstanceRef = useRef(null);
useEffect(() => {
let isMounted = true;
const initBetterbugs = async () => {
if (typeof window !== "undefined") {
const { default: Betterbugs } = await import("@betterbugs/web-sdk");
const instance = new Betterbugs({
// Replace with your BetterBugs Project API Key
apiKey: "YOUR-API-KEY-GOES-HERE",
});
if (isMounted) {
bbInstanceRef.current = instance;
}
}
};
initBetterbugs();
return () => {
isMounted = false;
bbInstanceRef.current?.destroy?.();
};
}, []);
// Example Component
return (
<>
<h1>BetterBugs Web SDK Widget | React</h1>
</>
);
}
export default App;4
Customize the SDK widget UI (Optional)
import { useEffect, useRef } from "react";
function App() {
// Initialization Code
const bbInstanceRef = useRef(null);
useEffect(() => {
let isMounted = true;
const initBetterbugs = async () => {
if (typeof window !== "undefined") {
const { default: Betterbugs } = await import("@betterbugs/web-sdk");
const instance = new Betterbugs({
// Replace with your BetterBugs Project API Key
apiKey: "YOUR-API-GOES-HERE",
// UI Customization Examples
position: { top: "20px", right: "20px" },
styles: {
primaryColor: "#e41c38",
primaryTextColor: "#fff",
theme: "light",
},
});
if (isMounted) {
bbInstanceRef.current = instance;
}
}
};
initBetterbugs();
return () => {
isMounted = false;
bbInstanceRef.current?.destroy?.();
};
}, []);
// Example Component
return (
<>
<h1>BetterBugs Web SDK Widget | React</h1>
</>
);
}
export default App;Last updated