Nextjs
Next.js is a React framework for building modern web applications with features such as server-side rendering (SSR), static site generation (SSG), and hybrid rendering. This guide explains how to integrate the SDK Loader into Next.js applications.
Environment setup
Create a file .env in the root of your project:
NEXT_PUBLIC_API_KEY=YOUR_API_KEYApp Router (Next.js 16+)
For the App Router, use the directive 'use client' to make sure the component runs on the client.
Example: app/sdk/page.tsx
'use client';
import { useEffect } from 'react';
import { loadSdk } from '@facephi/sdk-loader';
export default function SdkPage() {
useEffect(() => {
const initializeSdk = async () => {
const apiKey = process.env.NEXT_PUBLIC_API_KEY || '';
const sdkElement = await loadSdk({
apiKey,
containerId: 'sdk-container',
});
if (sdkElement) {
sdkElement.addEventListener('emitIDVIntegration', (event) => {
console.log('emitIDVIntegration:', event);
});
}
};
initializeSdk();
}, []);
return (
<main>
<section>
<div id="sdk-container" />
</section>
</main>
);
}Pages Router (Next.js 16+)
For the Pages Router, use next/dynamic with ssr: false to disable server-side rendering for the SDK component.
Example: pages/sdk.tsx
Styles
Add styles in your global CSS or in CSS modules:
For advanced styling options, consult the SDK Provider customization documentation.
Known issues
Hydration error (hydration mismatch)
Module not found
Next steps
SDK Configuration: Learn about all available configuration options
SDK Web Components: Explore the available widgets and their properties
Last updated