Getting this error trying to import useDimensions

i have this error trying to import useDimensions

241 |
242 | if (error instanceof InvalidPackageError) {
243 | throw new PackageResolutionError({
| ^
244 | packageError: error,
245 | originModulePath: from,
246 | targetModuleName: to,]

import { useDimensions } from “@react-native-community/hooks”;

export default function App() {
console.log(useDimensions());
return (

<View
style={{ width: “50%”, height: 100, backgroundColor: “dodgerblue” }}
>

);
}

Not a React Native developer, but:

  1. did you install the package?

    npm install @react-native-community/hooks

    or

    yarn add @react-native-community/hooks

  2. are you using React Native >= 0.59.0?

thanks i already solved it, i don’t know what the problem was but i restarted everything and it worked

1 Like

I still get same error (TypeError: 0, _hooks.useDimensions is not a function (it is undefined))
I did what you said but getting error

The function useDimensions() doesn’t exist anymore in the module “@react-native-community/hooks”.
You can use the equivalent function useWindowDimensions() from “react-native”.

import {useWindowDimensions} from "react-native";
2 Likes