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``;

Discuss this article on Twitter

Category:

types

Tags:

TypeScriptReact
Mobx

© 2012-2022, built with Next.js and Chakra UI

Instagramtwittergithubjoelmturner's DEV Profile