React Native - Value of type NSString cannot be converted to a ABI44_0_0YGValue
While working on a react native project I stumbled upon this error:
JSON value of "90vh" of type NSString cannot be converted to a ABI44_0_0YGValue. Did you forget the % or pt suffix?
What does ABI44_0_0YGValue mean? I have tried the pt suffix but the same error still appears. What could be the problem?
I am using styled components to add the width and height value to different elements:
import styled from 'styled-components/native';
const MainWrapper = styled.View`
height: 90vh;
width: ${(Dimensions. get('screen'). width)}px;
justify-content: center;
align-items: center;
background-color: red;
`
const ScreenTime = ( { navigation } ) => {
return (
<MainWrapper>
<Header>
<Paragraph>Screen Time</Paragraph>
</Header>
</MainWrapper>
);
};
Any help would be much appreciated!
Solution 1:
All dimensions in React Native are unitless, and represent density-independent pixels.
In other words, the error is being thrown because React Native is looking for a Number type, not a string. Unlike CSS for the web, the "vh" and "px" suffixes are meaningless here.
Try:
height: 90,
width: Dimensions.get('window').width,