Created
February 26, 2021 14:21
-
-
Save JaysonChiang/bafb13cd50da1bf0172ac745ab2f2367 to your computer and use it in GitHub Desktop.
TypeScript React Component with React.FC
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
interface ChildProps { | |
name: string; | |
onClick: () => void; | |
} | |
const Child: React.FC<ChildProps> = ({ name, onClick }) => { | |
return ( | |
<div> | |
{name} | |
<button onClick={onClick}>Click</button> | |
</div> | |
); | |
}; | |
export default Child; |
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 Child from './Child'; | |
const Parent = () => { | |
return ( | |
<Child name="jayson" onClick={() => console.log('test')}> | |
other children content here | |
</Child> | |
); | |
}; | |
export default Parent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment