skip to Main Content

Unhandled Runtime Error
Error: (0 , chakra_ui_react__WEBPACK_IMPORTED_MODULE_2_.useDisclosure) is not a function

im importing useDisclosure correctly from chakraUI but it says useDisclosure() not a function

here is my code
code for a sidebar/drawer component using ChakraUI

2

Answers


  1. Hay!

    Try this code and tell me if you get the same error.

    import React from 'react';
    
    import {
      Drawer,
      DrawerBody,
      DrawerFooter,
      DrawerHeader,
      DrawerOverlay,
      DrawerContent,
      DrawerCloseButton,
      useDisclosure,
      Button,
      Input,
    } from '@chakra-ui/react'
    
    
    const DrawerExample = () => {
      const { isOpen, onOpen, onClose } = useDisclosure()
      const btnRef = React.useRef()
    
      return (
        <>
          <Button ref={btnRef} colorScheme='teal' onClick={onOpen}>
            Open
          </Button>
          <Drawer
            isOpen={isOpen}
            placement='right'
            onClose={onClose}
            finalFocusRef={btnRef}
          >
            <DrawerOverlay />
            <DrawerContent>
              <DrawerCloseButton />
              <DrawerHeader>Create your account</DrawerHeader>
    
              <DrawerBody>
                <Input placeholder='Type here...' />
              </DrawerBody>
    
              <DrawerFooter>
                <Button variant='outline' mr={3} onClick={onClose}>
                  Cancel
                </Button>
                <Button colorScheme='blue'>Save</Button>
              </DrawerFooter>
            </DrawerContent>
          </Drawer>
        </>
      )
    }
    
    export default DrawerExample;
    

    If everything is ok, then try copying the imports and running your code

    Login or Signup to reply.
  2. If you are using NextJS make sure to use client component

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search