-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nextjs Target container is not a DOM element #105
Comments
@adham618 - it looks like the error message is missing, could you try reposting it? |
all I did is to write this
|
Thanks for providing the code example and screenshot. I'm not too familiar with Next.js SSR, but based on this stackoverflow post it sounds like you'll need to update the |
pls can you tell me what is wrong |
now it works in local but the same code not working in stackblitz |
@adham618 - could you instead check if the window is defined before rendering the component? Again, I'm not very familiar with nextjs so I'm not sure if this is a best practice or not, but the code is working for me on the example app you provided. import Head from 'next/head';
import styles from '../styles/Home.module.css';
import { PopupButton } from 'react-calendly';
//import ClientOnlyPortal from '../lib/ClientOnlyPortal';
export default function Home() {
return (
<div className={styles.container}>
{typeof window !== 'undefined' && (
<PopupButton
url="https://calendly.com/adham-tarek"
rootElement={document.getElementById('__next')}
text="Click here to schedule!"
/>
)}
</div>
);
} |
thanks, it worked fine with me now |
The above solution was causing an error for me:
The fix is to move the condition inside the attribute definition:
|
Maybe you can try importing the components using next/dynamic. This makes sure that the library is client dependent. import dynamic from "next/dynamic";
const PopupButttonComp = dynamic(
() => import("react-calendly").then((mod) => mod.PopupButton),
{
ssr: false,
}
); |
I got this error when using react-calendly in next.js. Server Error This error happened while generating the page. Any console logs will be displayed in the terminal window. What is the solution? |
Hey @ProspDev - if you are using the new See #158 (comment) for additional details. |
Hi, @tcampb . It works well for me. Thanks for your help. :) |
My code is as follows "use client"; import React from 'react'; export default function Calendly() { {typeof window !== 'undefined' && ( <PopupButton url="https://calendly.com/psoekdev" rootElement={document.getElementById('__next')} text="Click here to schedule!" /> )} ) } But I got this error. Unhandled Runtime Error I can't find solution. please help |
The code example assumes that you have an element in the document with an id of <div id="__next"></div> The For the typescript error you can use the non null assertion operator to tell the compiler that the value will not be null. |
It doesn't work |
#FIRST! make sure you have an html element with the same id as the one you're targeting in your rootElement prop. This can be the root div of the component where you want to use it or in the layout folder. Just make sure that is out of the way... Then Use dynamic Import to import the component where you want to use it. Below is my own working calendlyPop component file `import { PopupWidget } from "react-calendly"; import React from "react"; const CalendlyPop = () => { export default CalendlyPop;` Usage: Then you can simply render your component as such: Hope this helps. |
None of the above actually fixed my issue. I have managed to solve it here: https://stackoverflow.com/a/77369603/9553902 |
This also helped me solve the problem ! |
Its wokring const Calendly = () => { if (!rootElement) { return ( ); }; export default Calendly; |
You can use like this:
|
this worked for me, you're a life saver <3 |
in nextjs it gives me this error
@tcampb
any help?
The text was updated successfully, but these errors were encountered: