Skip to content

Instantly share code, notes, and snippets.

@stuf
Created March 21, 2018 13:58
Show Gist options
  • Save stuf/9670b0bcd66e8b9fa85ef06c635c4020 to your computer and use it in GitHub Desktop.
Save stuf/9670b0bcd66e8b9fa85ef06c635c4020 to your computer and use it in GitHub Desktop.
TSX component scaffold

TSX component scaffold

For convenience and example for whoever might be wondering about TypeScript and React.

Why separate import of SFC?

Because SFC<Props> is much more readable in a chunk of code than React.SFC<Props>

Why a separate type declarations file?

Because having type declarations mixed in your code makes it messier than it needs to be.

But what about Redux?

That'll be another gist.

export interface Props {
propName: string;
}
.Component {
border: solid 1px #f00;
}
import * as React from 'react';
import { SFC } from 'react';
import './component.scss';
const Component: SFC<Props> = ({ propName }) => (
<div className="Component">
Component
<code>{propName}</code>
</div>
);
export default Component;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment