Techiio-author
Started by Jake WiliamsSep 25, 2021

Open
How to display a react component that I created at the click of another react component

2 VIEWES 1 LIKES 0 DISLIKES SHARE
1 LIKES 0 DISLIKES 2 VIEWES SHARE

I created a react component which I would like when clicking on its button, another component to export is displayed in the app.js

1 Replies

Techiio-commentatorTanmay Banerjee replied 2 months ago0 likes0 dislikes

In the JSX you show and hide different components based on this state value:

function App() {
  const [state, setState] = useState('start')
  return (
    <div>
      {state === 'start' && (
        <AddTripButton addTrip={() => setState('add-trip') } />
      )}
      {state === 'add-trip' && <AnotherComponent />}
    </div>
  )
}

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance