import { useCallback, useRef, useState } from "react";
import { isFunction } from "../utils";
function useRefState(initialState) {
  const [state, setState] = useState(initialState);
  const ref = useRef(state);
  const setRefState = useCallback(
    (patch) => {
      setState((prevState) => {
        return isFunction(patch) ? patch(prevState) : patch;
      });
    },
    [state]
  );
  return [state, setRefState, ref];
}
export {
  useRefState as default
};
