【发布时间】:2018-11-10 07:27:22
【问题描述】:
这是我的代码
import React, {
Component
} from 'react'
import {
Body,
Text,
View
} from 'native-base'
import {
Icon
} from 'react-native-elements'
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
iconColour: "red"
}
}
func() {
console.warn("changed")
this.setState({
iconColor: "blue"
})
}
render() {
return (
<View>
<Text> textInComponent </Text>
<Icon name='map' color={this.state.iconColour} onPress=
{()=>this.func()}/>
</View>
)
}
}
我想在按下时改变图标的颜色
但是颜色没有更新
功能有效,状态改变,但视图未更新
我想我错过了一件简单的事情
我搜索了但我找不到类似的情况
我认为应该运行一个命令来渲染具有新属性的视图
感谢您的帮助
【问题讨论】:
标签: react-native