我需要用这样的自定义接口扩展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'}