"use strict";

exports.__esModule = true;
exports.default = useRefState;

var _react = require("react");

var _utils = require("../utils");

function useRefState(initialState) {
  var _useState = (0, _react.useState)(initialState),
      state = _useState[0],
      setState = _useState[1];

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