reactjs - React Antd Modal-egenskapen 'children' finns inte på typen 'IntrinsicAttributes & ModalProps'


Efter att ha uppgraderat till React 18 har jag följande problem med Antd.

När jag använder en komponent från Antd (Modal, Dialog, ...) får jag detta fel:

TS2322: Type '{ children: ReactNode; ref: ForwardedRef<unknown>; className: string; visible: true; onCancel: (() => void) | undefined; onOk: undefined; footer: null; closable: false; }' is not assignable to type 'IntrinsicAttributes & ModalProps'.   Property 'children' does not exist on type 'IntrinsicAttributes & ModalProps'.

Här är min komponent:

function TransitionsModal(props: Props): JSX.Element {
  const {
    open,
    onClose,
    children
  } = props;

  return (
    <div>
      {open &&
        <Modal
          className="flex items-center justify-center"
          visible={open}
          onCancel={onClose}
          onOk={undefined}
          footer={null}
          closable={false}>
          {children}
        </Modal>
      }
    </div>

  );
}

Och här är mina rekvisita:

type Props = {
  children: React.ReactNode,
  open: boolean,
  onClose?: () => void
}

Jag använder node 17.8.0

Svar #1

du bör använda

"@types/react": "17.0.39" 

istället för

"@types/react": "18.0.3"

eftersom react18 @types ännu inte är kompatibelt.

Relaterade artiklar