1

I want to have props interface with generic type. How do I provide the generic type at the time of calling this React component?

Eg:

interface Props<T> {
  value: T;
}

function MyReactComponent<T> (
  props: Props<T>
): JSX.Element {
    return <div> xyz </div>;
}

// Usage
// How do I provide the generic type parameter while calling MyReactComponent
function AnotherComponent(props: Props): JSX.Element {
  return (
    <div>
      <MyReactComponent value={123}/>
    </div>
  );
}
Anant_Kumar
  • 764
  • 1
  • 7
  • 23

0 Answers0