Created
July 5, 2023 20:03
-
-
Save ernestlv/a5662c2d5540d85464693fae0e639e9c to your computer and use it in GitHub Desktop.
#React conditional render
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
const Square = () => { // Root Functional Component | |
let [show, setShowMe] = React.useState(false); // React Hook | |
const click = () => { // 'this' points to window | |
setShowMe(!show); | |
} | |
console.log("render square"); | |
// View | |
return ( | |
<div style={{color:'white'}}> | |
<div style={{backgroundColor:'red'}}>Hello</div> | |
{ | |
show && (<div style={{backgroundColor:'blue'}}>World!!!</div>) | |
} | |
<button onClick={click}>show/hide</button> | |
</div> | |
); | |
} | |
const root = ReactDOM.createRoot(document.querySelector("#app")); | |
root.render(<Square />); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment