Inline If-Else with Conditional Operator in React JS

Oct 13, 2022 . Admin

Hello Friends,

In this article we will cover how to implement inline if-else with conditional operator in react js. This tutorial will give you a simple example of inline if-else with conditional operator using react js. if you want to see example of inline if-else in react js then you are the right place. This tutorial will give you a simple example of conditional operator using react js. you will do the following things for conditional operator using react js example.

In this example is inline if-else with conditional operator in react js. I will simple step by step explain how to use conditional operator in react js. As the inline condition suggests, we can write the condition in a single line.

So, let's start following example:

Step 1: Create React JS App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app reactjs-my-example
Step 2: Create index.js file src/index.js
import React, { useState } from "react";
import ReactDOM from "react-dom/client";

function User(){

    const [useLogin,setUseLogin] = useState(true);

    return (
        <div>l;
            The user is <b>l;{useLogin ? 'Login' : 'Not Login'}</b>l;.
        </div>l;
    );
	
}
  
const root = ReactDOM.createRoot(document.getElementById('root')); 

root.render(<User />l;);
Run React JS App:
npm start

Output:

I hope it can help you...

#React JS