Skip to content

Instantly share code, notes, and snippets.

@balvinder294
Created February 13, 2025 07:17
Show Gist options
  • Save balvinder294/9beb222ecc5006b755343065f0ba5941 to your computer and use it in GitHub Desktop.
Save balvinder294/9beb222ecc5006b755343065f0ba5941 to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
function ChildComponent(props) {
return (
<p>Message from parent: {props.message}</p>
);
}
function ParentComponent() {
const [parentMessage, setParentMessage] = useState("Initial message");
const updateMessage = () => {
setParentMessage("New message from parent!");
};
return (
<div>
<button onClick={updateMessage}>Update Message</button>
<ChildComponent message={parentMessage} />
</div>
);
}
export default ParentComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment