Next.js Discord

Discord Forum
\n \n \n );\n}wrapper.tsx\"use client\";\n\nimport { Excalidraw } from \"@excalidraw/excalidraw\";\n\nimport { useTheme } from \"next-themes\";\nimport { useEffect, useState } from \"react\";\n\nexport const ExcalidrawWrapper = () => {\n const { theme } = useTheme();\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n if (!mounted) {\n return null;\n }\n\n return (\n
\n \n
\n );\n};\n\nexport default ExcalidrawWrapper; ","dateCreated":"2025-02-08T06:08:29.785Z","answerCount":4,"author":{"@type":"Person","name":"ani"},"suggestedAnswer":{"@type":"Answer","text":"~im using bun btw~","url":"https://nextjs-forum.com/post/1337666347089268777#message-1337666889765355531","dateCreated":"2025-02-08T06:10:39.169Z","author":{"@type":"Person","name":"ani"}}}}

Cannot read properties of undefined (reading 'ReactCurrentDispatcher')

Unanswered
ani posted this in #help-forum
Open in Discord
aniOP
Trying to integrate excalidraw to my nextjs app

page.tsx -
import dynamic from "next/dynamic";
import Script from "next/script";

const ExcalidrawWithClientOnly = dynamic(
  async () => (await import("@/components/excalidraw/excalidraw-wrapper")).default,
);

export default function Page() {
  return (
    <>
      <a href="/excalidraw-in-pages">Switch to Pages router</a>
      <h1 className="page-title">App Router</h1>
      <Script id="load-env-variables" strategy="beforeInteractive">
        {`window["EXCALIDRAW_ASSET_PATH"] = window.origin;`}
      </Script>
      <ExcalidrawWithClientOnly />
    </>
  );
}


wrapper.tsx
"use client";

import { Excalidraw } from "@excalidraw/excalidraw";

import { useTheme } from "next-themes";
import { useEffect, useState } from "react";

export const ExcalidrawWrapper = () => {
  const { theme } = useTheme();
  const [mounted, setMounted] = useState(false);

  useEffect(() => {
    setMounted(true);
  }, []);

  if (!mounted) {
    return null;
  }

  return (
    <div style={{ height: "calc(100vh - 64px)", width: "100%" }}>
      <Excalidraw
        theme={theme === "dark" ? "dark" : "light"}
        initialData={{
          appState: {
            viewBackgroundColor: theme === "dark" ? "#121212" : "#ffffff",
          },
        }}
      />
    </div>
  );
};

export default ExcalidrawWrapper; 

4 Replies

aniOP
~im using bun btw~
aniOP
bump because i cant do shit i tried googling everywher
Skipjack tuna
Have you tried this?

const ExcalidrawWithClientOnly = dynamic(
async () => (await import('@/components/excalidraw/excalidraw-wrapper')).default,
{
ssr: false,
}
);
aniOP
yep but then nextjs throws error as ssr and dynamic import cant be done together