skip to Main Content

So I use Chakra in my Nextjs 13 project, I have this code:

const Home = () => {
  const color = useColorModeValue("telegram.500", "telegram.400");

  return <div>something here</div>
}

I get this error: Error: (0 , _chakra_ui_react__WEBPACK_IMPORTED_MODULE_2__.useColorModeValue) is not a function

Here is some info:

    "@chakra-ui/react": "^2.8.2",
    "@chakra-ui/react": "^2.8.2",

2

Answers


  1. This happens when you have imported it as default.

    You should import as:

    import {useColorModeValue}  from "@chakra-ui/react"; 
    

    not

    import useColorModeValue  from "@chakra-ui/react"; 
    
    Login or Signup to reply.
  2. Per this GH Discussion, the solution may be as simple as adding "use client" at top of your file.

    I can confirm that worked for me, although "use client" has its own complications, such as incompatibility with Next directives like Metadata… YMMV whether it’s a permanent solution, but at least it’s an explanation.

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