Skip to content

Instantly share code, notes, and snippets.

@jbutko
Last active July 8, 2020 19:15
Show Gist options
  • Save jbutko/a0c70c44b62f0e6194d2fe7271fa0e3d to your computer and use it in GitHub Desktop.
Save jbutko/a0c70c44b62f0e6194d2fe7271fa0e3d to your computer and use it in GitHub Desktop.
Stateless/dumb React component in Typescript
// stateless/dumb component in React Typescript
import * as React from 'react';
interface IWelcomeProps {
name: string,
}
const Welcome: React.SFC<IWelcomeProps> = ({ name }) => {
return <h1>Hello, {name}</h1>;
}
Welcome.defaultProps = {
name: 'Guest User', // This value is adopted when name prop is omitted
}
export default Welcome;
// via https://medium.com/@iktakahiro/react-stateless-functional-component-with-typescript-ce5043466011
// via https://firstdoit.com/how-to-write-a-react-stateless-functional-component-in-typescript-5d150419bbbc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment