我的组件正在返回一个封装在TableContainer
中的MUITable
const DataReleaseChart = (): React.FC<?> => {
return (
<TableContainer
sx={{
display: 'grid',
rowGap: 7,
}}
>
<Table>{chartRenderer(preCloseRowData)}</Table>
<Table>{chartRenderer(closedRowData)}</Table>
</TableContainer>
);
};
export default DataReleaseChart;
返回的类型应该是什么?
我试过ReactElement[]
,但它给出了的错误
Type 'Element' is missing the following properties from type 'ReactElement<any, string | JSXElementConstructor<any>>[]': length, pop, push, concat, and 29 more.ts(2740)
我也试过React.FC
,但得到了这个
Type 'Element' is not assignable to type 'FC<{}>'.
Type 'Element' provides no match for the signature '(props: { children?: ReactNode; }, context?: any): ReactElement<any, any>'.ts(2322)
**您可以使用ReactNode,并确保在声明函数时必须放入:FC**
import React, { FC, ReactNode } from "react";
const DataReleaseChart:FC<ReactNode> = () => {
return (
<TableContainer
sx={{
display: 'grid',
rowGap: 7,
}}
>
<Table>{chartRenderer(preCloseRowData)}</Table>
<Table>{chartRenderer(closedRowData)}</Table>
</TableContainer>
);
};
export default DataReleaseChart;