【发布时间】:2019-07-11 00:10:40
【问题描述】:
我正在使用 react native 构建约会应用程序,这是我在 RC 中的第一次尝试,使用 react-redux 来管理状态。我需要对生命周期方法进行一些说明。
Details.js
class Details extends Component {
constructor(props) {
super(props);
}
componentDidMount(){
this.props.bookingAndSuggestions(Data)
}
componentWillReceiveProps(nextProps){
if( Object.keys(nextProps.bookingSuggestionStatus).length >0) {
if(nextProps.bookingSuggestionStatus.res.data.status=='available') {
this.setState({isAvailable:false})
} else {
this.setState({isAvailable:true})
}} }
onBookNow=()=>{
this.props.shops(Data);
}
这是交易,最初我调用 react-redux action prop this.props.bookingAndSuggestions(Data) 并在 componentWillReceiveProps 中捕获响应,预订时 this.props.shops(Data); 将触发,它还会更新 componentWillrecieveprops,内部逻辑每次 props 发生变化时,componentwillrecieveprops 都会更新。处理这种情况的正确方法是什么?
【问题讨论】:
标签: reactjs react-native react-redux