bruno
August 27, 2022, 6:27pm
1
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:
did you install the package?
npm install @react-native-community/hooks
or
yarn add @react-native-community/hooks
are you using React Native >= 0.59.0?
bruno
August 27, 2022, 7:04pm
3
thanks i already solved it, i don’t know what the problem was but i restarted everything and it worked
1 Like
ezra
October 20, 2023, 1:00pm
4
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
As mentioned, useDimensions is no longer part of “@react-native-community /hooks”. This React native page explains how to get screen dimensions: