react-native - 如何在本机反应中将状态变量分配给样式组件?
问题描述
使用 react.js 可以将状态变量分配给 div 或任何其他元素,如下所示:
<div className={this.state.test}>
使用本机反应,我看不到如何实现相同的逻辑:
<Image style={this.state.test} />
本例中的测试变量 = 'styles.custom'
解决方案
//imports
class App extends Component {
state = {
width: 64 //random property
}
render() {
return <Image source={...} style={[styles.button, {...this.state}]}>
}
}
const styles = StyleSheet.create{
button: {
height: 64
}
}
推荐阅读
- python - Python 默认字典参考
- android - Glide:调整 ImageView 的大小以适应滑动中的图像,而不是相反
- amazon-web-services - 如何从 SNS 订阅中提取令牌并在确认订阅方法中使用它?
- wordpress - 自定义分类帖子名称未检索
- hyperledger-fabric - Hyperledger Fabric:/etc/hyperledger/fabric-ca-server/ca-chain.pem 中不存在链文件
- audio - 使用什么 ffmpeg 命令将无符号整数列表转换为音频文件?
- java - 如何在 Java 中使用 ComboBox 数据填充 ArrayList
- javascript - 发现奇怪的用户代理
- python - 如何从日志文件中提取java堆栈跟踪的时间戳?
- communication - 标准软件模式的 Word