- Create Components folder under src folder
- Add TernaryOperatorEXP1.js file and add below Code
import React, { useState } from "react";
const TernaryOperatorEXP1 = () => {
const [isLoggedIn, setIsLoggedIn] = useState(true);
return (
<div>
<h3>Ternary Operator Example </h3>
{isLoggedIn ? <div> Welcome User</div> : <div> You need to login</div>}
</div>
);
};
export default TernaryOperatorEXP1;
- Open App.js file and update code as below\
import React from "react";
import ReactDOM from "react-dom";
import TernaryOperatorEXP1 from "./components/TernaryOperatorEXP1";
function App() {
return (
<div className="App">
<TernaryOperatorEXP1 />
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
No comments:
Post a Comment