I am trying to fetch data from a JSON file and calculate a value, I saved the value using setState and I want to use it as the height of a React Native component (touchable opacity). I did managed to get the values however when I try to run the programme, an error pops up:
//JSON value '85.70' of type NSString cannot be converted to a ABI41_0_0YGValue.
//Did you forget the % or pt suffix?
I tried putting the value into styleSheet and it did not work. I'm pretty sure it is something about the type of the value. How can I convert the type NSString into ABI41_0_0YGValue? Below is my attempt:
const [value, setValue] = useState(0)
const [isLoading, setLoader] = useState(true)
const fetching = async () => {
...//code that fetches the value
setValue(value)
setLoader(false)
}
if (isLoading) {
return (
<Text> Loading...</Text>
)
}
return (
<View>
<TouchableOpacity
style={{height: value, width:30, backgroundColor: "red" }} />
... //other parts of the return statement
</View>
)
Any help will be appreciated!
You are passing the value as a string, just convert it to a number before saving it:
setValue(parseFloat(value))