Skip to content

Instantly share code, notes, and snippets.

@adityatyagi
Created June 7, 2022 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityatyagi/d460d85f4acfdec33607d4c918296715 to your computer and use it in GitHub Desktop.
Save adityatyagi/d460d85f4acfdec33607d4c918296715 to your computer and use it in GitHub Desktop.
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