我正在尝试使用 forwardRef 找出 Dot Notation 组件的类型。
所以我发现这个例子完美地说明了我目前如何使用点表示法,但不包括 forwardRef:https ://codesandbox.io/s/stpkm
这就是我想要实现的目标,但无法弄清楚类型。
import { forwardRef, useImperativeHandle } from "react";
//
import { ForwardRefRenderFunction } from "react";
const TabToggle: React.FC = () => null;
const TabContent: React.FC = () => null;
interface TabsStatic {
Toggle: typeof TabToggle;
Content: typeof TabContent;
}
export interface TabsProps {
initialIndex?: number;
}
export interface TabsRefMethods {
show: () => null;
hide: () => null;
}
export const Tabs: React.ForwardRefRenderFunction<
TabsRefMethods,
TabsProps & TabsStatic
> = forwardRef((props, ref) => {
const openFn = () => null;
const closeFn = () => null;
useImperativeHandle(ref, () => ({ show: openFn, hide: closeFn }));
return null;
});
Tabs.Toggle = TabToggle;
Tabs.Content = TabContent;
代码沙盒演示:https : //codesandbox.io/s/jsx-dot-notation-in-typescript-with-react-forked-38e1z? file =/ src / Tabs.tsx