NextJs 13.2 中的 React 上下文

Ale*_*ner 5 next.js react-context

我尝试在 NextJs 13 中使用 React 上下文,但遇到了错误 在此输入图像描述

这是我的背景 -

'use client';
import { MutableRefObject, createContext, useRef, useContext } from "react";

interface ContextProviderProps{
    children: React.ReactNode;
  }

const GlobalContext = createContext({});

export const ContextProvider:React.FC<ContextProviderProps> = ({children}) => {
    const ref = useRef< MutableRefObject<HTMLElement>>(null);

 return (
    <GlobalContext.Provider value={ref}>
        {children}
    </GlobalContext.Provider>
 )
}

export const useGlobalContext = () => useContext(GlobalContext);
Run Code Online (Sandbox Code Playgroud)

然后我包装我的布局 -

export default function RootLayout({children}: LayoutProps) {
 
  return (
    <html className={`h-screen snap-y snap-mandatory scroll-smooth overflow-y-auto hide-scrollbar ${inter.className}`} lang="ru">
      <body className='text-lg px-3 py-6 max-w-7xl mx-auto my-0 bg-[#000] text-[#f2d6d6]'>
        <ContextProvider>
          {children}
        </ContextProvider>
      </body>
    </html>
  )
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 我是 13 版本的新用户,我也尝试在页面中使用“uce client”,但没有成功。请帮忙!