父组件中#### 函数调用子组件
import React, { useState } from "react";
type CONTENT = (props?: { isSticky: boolean; [x: string]: any }) => JSX.Element;
export default (props: {
content?:CONTENT;
}) => {
const {
content
} = props;
const [isSticky, setIsSticky] = useState<boolean>(false);
return (
<div
>
//函数调用子组件
{content({ isSticky })}
</div>
);
};
父组件中#### JSX渲染子组件
import React, { useState } from "react";
type CONTENT = (props?: { isSticky: boolean; [x: string]: any }) => JSX.Element;
export default (props: {
content?: Content = () => null
}) => {
const {
content
} = props;
const [isSticky, setIsSticky] = useState<boolean>(false);
return (
<div
>
//JSX渲染
<Content isSticky={isSticky} />
</div>
);
};
函数调用子组件{content({ isSticky })}不会导致组件重新渲染。
JSX渲染 会导致组件重新渲染
AI回答: 可恶,怎么不给复制粘贴了,不写了