import React, { MutableRefObject, useCallback, useRef } from 'react';

/**
 * useState usando ref
 *
 * @param initial
 */
export function useStateRef<S = any>(initial: S): [MutableRefObject<S>, (v: S) => void] {
   const ref = useRef<S>(initial);
   const setRef = useCallback((v: S) => {
      ref.current = v;
   }, []);

   return [ref, setRef];
}
