Skip to content

Instantly share code, notes, and snippets.

@amitmbee
Forked from jbutko/statelessComponent.tsx
Created June 29, 2018 05:05
Show Gist options
  • Save amitmbee/b15d2741abc146a5e15422c7b9de5325 to your computer and use it in GitHub Desktop.
Save amitmbee/b15d2741abc146a5e15422c7b9de5325 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