Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Created February 13, 2019 03:47
Show Gist options
  • Save jrwebdev/a8b66c5a8b633ae83c3d45fe70b63604 to your computer and use it in GitHub Desktop.
Save jrwebdev/a8b66c5a8b633ae83c3d45fe70b63604 to your computer and use it in GitHub Desktop.
// inferred as number
const [value, setValue] = useState(0);
// explicitly setting the types
const [value, setValue] = useState<number | undefined>(undefined);
const [value, setValue] = useState<Array<number>>([]);
interface MyObject {
foo: string;
bar?: number;
}
const [value, setValue] = useState<MyObject>({ foo: 'hello' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment