Created
June 7, 2022 14:26
-
-
Save adityatyagi/d460d85f4acfdec33607d4c918296715 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 React, { useState } from "react"; | |
import { render } from "react-dom"; | |
// Functional component | |
const DemoOutput = (props) => { | |
return ( | |
<div> | |
<h3>This is demo output component and will remain static</h3> | |
<p>{props.show ? "Only this will render" : ""}</p> | |
</div> | |
); | |
}; | |
// Main App component | |
const App = (props) => { | |
const [showPara, setShowPara] = useState(false); | |
const togglePara = () => { | |
setShowPara((state) => !state); | |
}; | |
return ( | |
<div> | |
<h2>Virtual DOM demo by Aditya Tyagi</h2> | |
<DemoOutput show={showPara} /> | |
<button onClick={togglePara}>Toggle</button> | |
</div> | |
); | |
}; | |
render(<App messages={data.messages} />, document.getElementById("root")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment