Created
September 2, 2025 06:29
-
-
Save VivekSaha/e423c0c3ca318e4c9fe183d7c26ce90f to your computer and use it in GitHub Desktop.
React - useState Multiple Condition using Ternary Operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react" | |
const App = () => { | |
const [counter, setCounter] = useState(0); | |
const handleClick = () => { | |
setCounter(counter + 1); | |
} | |
return( | |
<> | |
<h1>useState Multiple Condition using Ternary Operator</h1> | |
{ | |
counter == 0 ? <p>Condition 1</p> | |
: counter == 1 ? <p>Condition 2</p> | |
: counter == 2 ? <p>Condition 3</p> | |
: <p>Out of Range</p> | |
} | |
<button onClick={handleClick} disabled={counter > 2}>Click Here</button> | |
</> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment