import { useCallback, useRef, useState } from 'react';
import { isFunction } from '../utils';
export default function useRefState(initialState) {
  var _useState = useState(initialState),
      state = _useState[0],
      setState = _useState[1];

  var ref = useRef(state);
  var setRafState = useCallback(function (patch) {
    setState(function (prevState) {
      // eslint-disable-next-line no-return-assign
      return ref.current = isFunction(patch) ? patch(prevState) : patch;
    });
  }, [state]);
  return [state, setRafState, ref];
}