import { RootProvider } from 'fumadocs-ui/root-provider';<RootProvider search={{ hotKey: [ { display: 'K', key: 'k', // key code, or a function determining whether the key is pressed }, ], }}> {children}</RootProvider>;
'use client';import SearchDialog from 'fumadocs-ui/components/dialog/search-default';import type { SharedProps } from 'fumadocs-ui/components/dialog/search';export default function CustomDialog(props: SharedProps) { // your own logic here return <SearchDialog {...props} />;}
要将其传递给 Root Provider,您需要一个带有
use client
指令的包装器。
'use client';import { RootProvider } from 'fumadocs-ui/provider';import dynamic from 'next/dynamic';import type { ReactNode } from 'react';const SearchDialog = dynamic(() => import('@/components/search')); // lazy loadexport function Provider({ children }: { children: ReactNode }) { return ( <RootProvider search={{ SearchDialog, }} > {children} </RootProvider> );}
使用它替代您之前的 Root Provider
import { Provider } from './provider';import type { ReactNode } from 'react';export default function Layout({ children }: { children: ReactNode }) { return ( <html lang="en"> <body> <Provider>{children}</Provider> </body> </html> );}