简体   繁体   中英

Want to render different component after click on Add Button

I want to render VehicleInfoRender.js when click on 'Add' button which is in UMUIMAdditionalCoverage.js

App.js

import './App.css';

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

export default App;

Use state (eg: isShowVehicleInfoRender ) to handle turn on/off render this component

First add a state to manage toggling VehicleInfoRender

state = { activeIndex: 0,  showVehicleInfo: false}

Then add a function to toggle showing and hiding the component

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

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

Finally add this where you want to render the component

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM