Skip to content

Commit

Permalink
feat: improve useSetState() typings
Browse files Browse the repository at this point in the history
Fix useSetState callback parameter type
  • Loading branch information
streamich authored May 30, 2019
2 parents e63ef6e + eeb05e9 commit fad4440
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/useSetState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

const useSetState = <T extends object>(initialState: T = {} as T): [T, (patch: Partial<T> | (() => void)) => void] => {
const useSetState = <T extends object>(initialState: T = {} as T): [T, (patch: Partial<T> | ((prevState: T) => Partial<T>)) => void] => {
const [state, set] = useState<T>(initialState);
const setState = patch => {
set(prevState => Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch));
Expand Down

0 comments on commit fad4440

Please sign in to comment.