Skip to content

Instantly share code, notes, and snippets.

@naveedahmed986
Created January 14, 2021 10:25
Show Gist options
  • Save naveedahmed986/2be1a05a0350baab91dba8f17135c93f to your computer and use it in GitHub Desktop.
Save naveedahmed986/2be1a05a0350baab91dba8f17135c93f to your computer and use it in GitHub Desktop.
react-parent-child-data-binding
import React from "react";
import Child from "./child";
export default function Parent() {
const [parentInput, setParentInput] = React.useState();
const [childInput, setChildInput] = React.useState();
return (
<div className="Parent">
<h4>Parent</h4>
<input
value={parentInput}
placeholder="input to child..."
onChange={(e) => setParentInput(e.target.value)}
/>
<br />
<span>{childInput}</span>
<div className="Center">
<Child toChild={parentInput} fromChild={setChildInput} />
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment