我试图像这样使用React.memo:
const Node: React.memo<Props> = props => {
但我说错了:
Namespace '../ui/node_modules/@types/react/index.d.ts"' has no exported member 'memo'.
但是我可以在index.d.ts中看到备忘录函数:
function memo<P extends object>(
Component: SFC<P>,
propsAreEqual?: (prevProps: Readonly<PropsWithChildren<P>>, nextProps: Readonly<PropsWithChildren<P>>) => boolean
): NamedExoticComponent<P>;
function memo<T extends ComponentType<any>>(
Component: T,
propsAreEqual?: (prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean
): MemoExoticComponent<T>;我在这里错过了什么?
发布于 2019-09-04 21:41:23
正如注释中提到的,memo不是类型声明。你的语法有点混乱
const Node: React.FC<Props> = React.memo(props => {
return(
<div>
memoized
</div>
)
})注意,React.FC是一个函数组件的声明。因为您将它包装在一个memo中,所以您可能需要更改类型。但就我个人而言,我不需要这么做。
https://stackoverflow.com/questions/57788199
复制相似问题