Created
January 14, 2021 10:25
-
-
Save naveedahmed986/2be1a05a0350baab91dba8f17135c93f to your computer and use it in GitHub Desktop.
react-parent-child-data-binding
This file contains hidden or 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 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