Skip to content

Instantly share code, notes, and snippets.

@schneidmaster schneidmaster/react.d.ts
Last active Oct 31, 2018

Embed
What would you like to do?
Typescript definitions for React hooks
// Typescript definitions for React hooks
// Take with a grain of salt; these are a first attempt and I've only actually
// used a few so far :)
import { Context, RefObject } from 'react';
declare module 'react' {
export function useState<T>(initialValue: T): [T, (newState: T) => void];
export function useEffect(effect: Function, inputs?: Array<any>): void;
export function useMutationEffect(effect: Function, inputs?: Array<any>): void;
export function useLayoutEffect(effect: Function, inputs?: Array<any>): void;
export function useContext<T>(context: Context<T>): any;
export function useReducer<T>(
reducer: (state: T, action: Object) => T,
initialState: T,
initialAction?: Object,
): [T, (action: Object) => void];
export function useCallback(callback: Function, inputs: Array<any>): Function;
export function useMemo<T>(memoized: Function, inputs: Array<any>): T;
export function useRef<T>(initialValue?: any): RefObject<T>;
export function useImperativeMethods<T>(
ref: RefObject<T>,
createInstance: () => Object,
inputs?: Array<any>
): void;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.