我正在try 将一些用更老的版本(我认为是14或16)编写的ReactJS代码转换为18,并且代码多次使用pros.Child,这在较新版本的ReactJS中已被删除.我已经找到了很多解决这个问题的教程,but I can only find ones that refer to functional components, not classes.
export class SystemStatusContainer extends React.Component<
{},
{
status: systemStatuses;
pollStatus: boolean;
}
> {
state = {
status: systemStatuses.online,
pollStatus: true,
};
timer: NodeJS.Timeout;
.
.
.
render() {
const { status } = this.state;
if (status === systemStatuses.offline) {
return <SystemUnavailableModal />;
} else if (status === systemStatuses.update) {
return <SystemStatusModal />;
} else {
return this.props.children;
}
}
如何将底线this.pros.Child转换为在ReactJS18中工作?我在网上找到的所有方法都涉及将子元素直接传递到组件中,但只有当它是一个功能组件,而不是一个类(据我所知)时,这才有效.
NOTE:这段代码不是我的,正因为如此,我试图尽可能地减少更改.如果代码中有与此问题无关的问题,请不要提出,除非它们会直接影响this.pros.Child的问题.