Skip to content

Instantly share code, notes, and snippets.

@chadmuro
Last active October 24, 2021 12:16
Show Gist options
  • Save chadmuro/d468ef7d5029182a50ca1803e1060e9a to your computer and use it in GitHub Desktop.
Save chadmuro/d468ef7d5029182a50ca1803e1060e9a to your computer and use it in GitHub Desktop.
useState Type
/**
* Returns a stateful value, and a function to update it.
*
* @version 16.8.0
* @see https://reactjs.org/docs/hooks-reference.html#usestate
*/
function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
// convenience overload when first argument is omitted
/**
* Returns a stateful value, and a function to update it.
*
* @version 16.8.0
* @see https://reactjs.org/docs/hooks-reference.html#usestate
*/
function useState<S = undefined>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment