MDLAB 기록/차량부품거래애플리케이션
[React Native -25] refresh 하기
지유미
2023. 3. 3. 19:38
728x90
반응형
상품을 숨김 버튼을 클릭했을때 Home으로 가면서 refresh되어야 홈에 있던 상품이 없어지게 된다
즉, Home으로 갈때 상품을 불러오는 API를 다시 호출을 해야한다
<Home>
Home에서 Item_Detail로 갈 때 부품목록을 호출하는 메소드인 refresh함수를 props로 전달한다
goGoodsDetailScreen=()=> {
this.props.navigation.push('GoodsDetail',{id:this.props.item.id, userID:this.props.item.userID, refresh:this.goGetGoods});
}
//부품 목록 호출 메서드
goGetGoods = () => {
this.setState({indicator : true});
this.callGetGoodsAPI().then((response) => {
this.contents = response;
this.setState({indicator:false,goodsContent:response});
});
this.setState({ refreshing: false })
}
<Item_Detail>
Home에서 전달받은 함수를 상품을 숨김을 완료했을 때 실행하도록 한다.
//숨김버튼 클릭
goodsDisableButtonClicked=()=>{
Alert.alert(
'',
'상품을 숨기겠습니까?',
[
{ text: '취소', onPress: () => console.log('Cancel Pressed') },
{
text: '확인', onPress: () => this.callSetDisableGoodsAPI().then((response) => {
console.log("숨김완료", response);
if(response.success==1){
this.props.navigation.navigate("Home");
this.refresh();
}
})
},
],);
}
// Home refresh
refresh =()=>{
this.props.route.params.refresh();
}
728x90
반응형