Typescript接口扩展React.FC



我需要用这样的自定义接口扩展React.FC:

interface IComponent<P = {}> extends React.FC {
custom?: {a: string, b: string};
}
const Page:IComponent<{text: string}> = ({text}) => (
<>{text}</>
)
Page.custom = {a: '1', b: '2'}

Page.custom输入正确,但React.FC道具功能丢失。我该如何解决这个问题?

我明白了。我需要将P参数从IComponent传递到React.FC

interface IComponent<P = {}> extends React.FC<P> {
custom?: {a: string, b: string};
}

try without{}

add typestring


interface IComponent<P = {}> extends React.FC {
custom?: {a: string, b: string};
}
const Page:IComponent<{text: string}> = (text:string) => (
<>{text}</>
)
Page.custom = {a: '1', b: '2'}

最新更新