I am using this.setState to update state in my component, but something wrong with this, the callback of this.setState is also not executed. here is my code:
{
this.state.monthData.map((item, index) => (
<TouchableOpacity onPress={() => this.openMessage(item, index)}
style={[styles.calendarItem,
this.state.activeIndex === index ? {
borderWidth: 1,
borderColor: 'red',
} : {}]}
>
<Text style={styles.dayTitle}>{item.cDay}</Text>
<Text style={styles.dayLunar}>{item.Term ?? item.IDayCn}</Text>
<View style={styles.underline}/>
</TouchableOpacity>
))
}
constructor (props) {
super(props)
this.state = {
monthData: [],
offsetMargin: 0,
activeIndex: null,
}
}
openMessage = (item, index) => {
console.log('index', index) // output correctly
this.setState({
activeIndex: index
}, function (){
console.log('set success') // here is not executed
})