Last active
November 6, 2021 19:03
-
-
Save UsmanHaider15/e9694bfb666a94d5bf26510aaff1f2ab to your computer and use it in GitHub Desktop.
This file contains 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 Switch = ({ test, children }) => | |
children.find((child) => child.props.value === test); | |
function SwitchComponent() { | |
const [value, setValue] = useState("first"); | |
return ( | |
<div> | |
<Switch test={value}> | |
<div value="first">This is First Case</div> | |
<div value="second">This is Second Case</div> | |
</Switch> | |
<br /> | |
<div> | |
<button onClick={() => setValue("first")}>First</button> | |
<button onClick={() => setValue("second")}>second</button> | |
</div> | |
</div> | |
); | |
} | |
export default SwitchComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment