I’m struggling to integrate Calendly into my Next.js 13.5 application. I’ve attempted multiple methods but keep running into different errors. Could someone point me in the right direction?
Method 1: Direct Script Integration
First, I tried using Calendly’s native script approach:
"use client";
import Head from "next/head";
import React, { useEffect } from "react";
export default function BookingWidget() {
useEffect(() => {
window.Calendly.createInlineWidget({
url: "my-calendly-url",
parentElement: document.querySelector("#booking-container"),
});
});
return (
<>
<Head>
<script
src="https://assets.calendly.com/assets/external/widget.js"
type="text/javascript"
async
></script>
</Head>
<div
id="booking-container"
style={{ minWidth: 300, height: 600 }}
data-auto-load="false"
></div>
</>
);
}
This gives me an error:
TypeError: Cannot read properties of undefined (reading 'createInlineWidget')
Method 2: React Calendly Package
Then I switched to the react-calendly npm package, but got this error:
Error: Object prototype may only be an Object or null: undefined
I’ve been debugging this for hours and can’t figure out what’s causing these issues. Has anyone successfully embedded Calendly in Next.js 13? Any suggestions would be greatly appreciated!