joelmturner pyramid logo

About

Blog

Illustration

TIL

Uses

About

Blog

Illustration

TIL

Uses

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

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

InstagramtwitterlinkedIngithubjoelmturner's DEV Profilejoelmturner's Mastodon Profile