Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chakra UI type problem with useDisclosure

I'm trying to use the alert dialog example from chakra ui docs, but I got some issues with typing:

    const { isOpen, onOpen, onClose } = useDisclosure();
    {...}
        <AlertDialog
                    motionPreset="slideInBottom"
                    leastDestructiveRef={cancelRef}
                    onClose={onClose}
                    isOpen={isOpen}
                    isCentered
        >
                <Button ref={cancelRef} onClick={onClose}>
                    Cancel
                </Button>
        </AlertDialog>

I got the following errors from the leastDestructiveRef and ref:

Type 'MutableRefObject' is not assignable to type 'RefObject'.

Type 'MutableRefObject' is not assignable to type 'LegacyRef | undefined'.

like image 207
Raphael Jayme Avatar asked Oct 17 '25 10:10

Raphael Jayme


1 Answers

I had the same issue with Chakra. As in Linda Paiste's answer, this fixed it for me:

import { useRef } from 'react';
...
const cancelRef = useRef<HTMLButtonElement>(null);
like image 183
Robert Rendell Avatar answered Oct 20 '25 01:10

Robert Rendell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!