Home > Back-end >  How to convert value inside functional component based on generic type
How to convert value inside functional component based on generic type

Time:12-15

I have the following component:

// ...

type StringOrNumber = string | number;

type InputProps<T extends StringOrNumber> = {
  value: T;
  onSubmit: (value: T) => void;
};

export default function Input<T extends StringOrNumber>(props: InputProps<T>) {
  const [value, setValue] = useState(props.value.toString());

  // Called on enter & blur
  const submitValue = () => {
    //            
  • Related