Last active
August 11, 2021 13:43
-
-
Save iKunalmathur/b2c427fe2a7b63cdf24fb1bd1b10d1a0 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 { useState } from "react"; | |
// Parent Component | |
export default function Parent() { | |
// a variable with default value of 0 | |
let a = 1; | |
return ( | |
<div> | |
<h1>👪 Parent Component</h1> | |
<Child a={a} /> | |
</div> | |
); | |
} | |
interface ChildProps { | |
a: number; | |
} | |
// Child Component | |
export function Child({ a }: ChildProps) { | |
const [state, setstate] = useState<number>(a); | |
return ( | |
<div> | |
<h2>👶 Child Component</h2> | |
<p>🎯 Count : {state}</p> | |
<button onClick={() => setstate(state + 1)}>button</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment