How to conditionally return JSX from react components

How to conditionally return JSX from react components

Example

import React, { useState } from "react";

export default function App() {

  const [user, setUser] = useState(false);

  return user ? <Profile /> : <Login />;
}

const Profile = () => {
  return <h1>This is profile page</h1>;
};

const Login = () => {
  return <h1>This is login page</h1>;
};

 

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