簡體   English   中英

想要在點擊添加按鈕后呈現不同的組件

[英]Want to render different component after click on Add Button

我想在單擊 UMUIMAdditionalCoverage.js 中的“添加”按鈕時呈現 VehicleInfoRender.js

應用程序.js

import './App.css';

const App = () => {
  return (
    <BasicLayout />
  );
}

export default App;

使用 state(例如: isShowVehicleInfoRender )來處理打開/關閉渲染此組件

首先添加一個 state 來管理切換VehicleInfoRender

state = { activeIndex: 0,  showVehicleInfo: false}

然后添加一個 function 來切換顯示和隱藏組件

<Button onClick={this.toggleVehicleInfo}>Add</Button>

const toggleVehicleInfo = () => {
 this.setState((prevState) => {showVehicleInfo: !prevState.showVehicleInfo});
};

最后將其添加到您要渲染組件的位置

{this.state.showVehicleInfo && <VehicleInfoRender />}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM