【发布时间】:2021-07-07 12:34:27
【问题描述】:
我正在尝试从 JSON 文件中获取数据并计算一个值,我使用 setState 保存了该值,我想将其用作 React Native 组件的高度(可触摸不透明度)。我确实设法获得了值,但是当我尝试运行程序时,会弹出一个错误:
//JSON value '85.70' of type NSString cannot be converted to a ABI41_0_0YGValue.
//Did you forget the % or pt suffix?
我尝试将值放入 styleSheet 中,但没有成功。我很确定这与值的类型有关。如何将 NSString 类型转换为 ABI41_0_0YGValue?以下是我的尝试:
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>
)
任何帮助将不胜感激!
【问题讨论】:
标签: reactjs react-native setstate touchableopacity