React Native
생명주기 componentWillReceiveProps
Machine_웅
2020. 4. 23. 09:59
728x90
반응형
change_list(list){
this.setState({
datalist:list,
selectedItem:list[0]
})
}
componentWillReceiveProps(nextProps) {
// this.props 는 아직 바뀌지 않은 상태
console.log("componentWillReceiveProps!!!!!!!!!!!!!!!!!!!")
if(this.state.datalist[0].value != nextProps.items[0].value){
console.log("새로운 리스트 !")
this.change_list(nextProps.items)
}else{
console.log("기존 리스트 !")
}
}
728x90
반응형