import { useState, useCallback } from '@tarojs/taro';
import { BaseEventOrig } from '@tarojs/components/types/common';

function useInputValue(initialValue: string) {
  let [value, setValue] = useState(initialValue);
  let onChange = useCallback(function(
    event: BaseEventOrig<{
      value: string;
      cursor: number;
      keyCode: number;
    }>,
  ) {
    setValue(event.detail.value);
  }, []);

  return {
    value,
    onChange,
    setValue,
  };
}

export default useInputValue;
