Conditionally apply display block and show in reactjs

How to conditionally apply display block and show

Example

import React, { useState } from "react";

export default function App() {
  const [show, setShow] = useState(false);

  return (
    <>

      <div style={{ display: show ? "none" : "block" }}>

        <h1>First page</h1>
        <button onClick={() => setShow(true)}>Show Second Page</button>

      </div>

      <div style={{ display: show ? "block" : "none" }}>

        <h1>Second page</h1>

      </div>

    </>
  );
}

 

About Author

Photo

Hi, I am Mahbub Hasan
Software Engineer

I am very much interested to share my programming
and development knowledge with the people.I will try
to update my blog everyday with new technology inshallah.

Thank You

For Visiting My Blog.

Contact Me