import { useState } from "react";

export default function usePatchableState<T>(
  initialState: T
): [
  state: T,
  patchState: (partialValue: Partial<T>) => void,
  setState: (value: T) => void
] {
  const [state, setState] = useState(initialState);
  function patchState(partialValue: Partial<T>) {
    setState({ ...state, ...partialValue });
  }

  return [state, patchState, setState];
}
