Created
March 21, 2023 04:48
-
-
Save gtchakama/6d4a523395189cdefc834460714aa59a to your computer and use it in GitHub Desktop.
Simple component Selector using select options
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 React, { useState } from "react"; | |
import ComponantA from "./ComponantA"; | |
import ComponantB from "./ComponantB"; | |
import ComponantC from "./ComponantC"; | |
function ChangeComponantSelect(){ | |
const [selected,setSelected]=useState('First Componant') | |
const handleChange=(e)=>{ | |
console.log(e.target.value) | |
setSelected(e.target.value) | |
} | |
return( | |
<div> | |
<select className="Space" value={selected} onChange={(e)=>handleChange(e)}> | |
<option>First Componant</option> | |
<option>Second Componant</option> | |
<option>Third Componant</option> | |
</select> | |
{selected == "First Componant"?<ComponantA/>:"" } | |
{selected == "Second Componant"?<ComponantB/>:"" } | |
{selected == "Third Componant"?<ComponantC/>:"" } | |
</div> | |
); | |
} | |
export default ChangeComponantSelect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment