Skip to content

Instantly share code, notes, and snippets.

@iKunalmathur
Last active August 11, 2021 13:43
Show Gist options
  • Save iKunalmathur/b2c427fe2a7b63cdf24fb1bd1b10d1a0 to your computer and use it in GitHub Desktop.
Save iKunalmathur/b2c427fe2a7b63cdf24fb1bd1b10d1a0 to your computer and use it in GitHub Desktop.
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