我有下面的代码。如何将它从类组件转换为功能组件,注意我想使用接口而不是类型?同样,我相信不需要空类型的道具,对吧?
import { v4 as uuidv4 } from 'uuid';
type Props = {};
type State = {
hasError: boolean;
guid: string;
};
export class ErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
hasError: false,
guid: uuidv4(),
};
}
render() {
if (this.state.hasError) {
return <>Error</>;
}
return this.props.children;
}
}
};