React TypeScript


Hooks

// add type before parens
React.useState<boolean>(false);
React.useRef<HTMLDivElement>(null);
React.useCallback(
function () {
if (theMoon) {
setSomethingAwesome();
}
},
[theMoon],
);

Props

type FooProps = {
children: React.ReactNode;
};

Components

// functional
const Foo: React.FC<FooProps> = (props) => ()
// class
class Foo extends React.Component<FooProps> {}

emotion

const Foo = styled<FooProps>.div``;
< Mobx Storybook >