Last active
October 31, 2018 17:08
-
-
Save schneidmaster/0a6aa5a65c753e851346b6130841d571 to your computer and use it in GitHub Desktop.
Typescript definitions for React hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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