Skip to content

Instantly share code, notes, and snippets.

@zeekrey
Created November 29, 2019 20:11
Show Gist options
  • Save zeekrey/94fd34fae2f16c76a00ad26e83091310 to your computer and use it in GitHub Desktop.
Save zeekrey/94fd34fae2f16c76a00ad26e83091310 to your computer and use it in GitHub Desktop.
[Typescript Functional Component Template] This is just my template for a new functional component written in React and Typescript. #react #typescript #functional-component
import React, { useState, useEffect, FunctionComponent } from "react"
import PropTypes from "prop-types"
type SubscribeProps = {
title: string
paragraph?: string
}
const Subscribe: FunctionComponent<SubscribeProps> = ({
title,
paragraph = "default",
children,
}) => {
// Component state
const [status, setStatus] = useState("initalValue")
// Sideeffects like onLoad and stuff
useEffect(() => {
document.title = `Hello ${name}`
}, [name])
return <div>hi</div>
}
Subscribe.propTypes = {
title: PropTypes.string.isRequired,
paragraph: PropTypes.string,
}
export default Subscribe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment