![](/img/trans.png)
[英]How to stop a child component from re-rendering a parent component in react native?
[英]How to stop the previous component from rendering when it is redirected to another component in react
所以我有兩個組件:
初始 state 看起來像這樣:
const initialState = {
data: [],
loading: false,
error: ''
};
當我獲取所有手機時,它存儲在 state.data 中。 當用戶點擊手機時,它的 id 被發送到組件 Mobile detail
viewDetails(id) {
this.props.history.push("/detail", { selectedMobile: id });
}
現在,在手機詳細信息組件中,我獲取手機的詳細信息並嘗試將其存儲在 state.data 中。
componentDidMount() {
const selectedMobile = this.props.location.state.selectedMobile;
this.props.loadMobile(selectedMobile);
}
<Layout>
<Switch>
<div>
<Route path="/detail" component={MobileDetail} />
<Route path="/" component={Mobile} />
</div>
</Switch>
</Layout>
如果您看到下圖,則移動詳細信息組件也在加載移動組件。 這背后的原因可能是什么?
將您的 App.js 更改為此
<Layout>
<Switch>
<Route path="/detail" component={MobileDetail} />
<Route path="/" component={Mobile} />
</Switch>
</Layout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.