[React Typescript] Generic function component

发布时间 2023-08-11 15:06:21作者: Zhentiw
export const Table = <T>(props: TableProps<T>) => {
  return (
    <table>
      <tbody>
        {props.rows.map((row) => (
          <tr>{props.renderRow(row)}</tr>
        ))}
      </tbody>
    </table>
  );
};

 

Because ti's a tsx file, the way to fix it:

export const Table = <T,>(props: TableProps<T>) => {

or 

export const Table = <T extends unknown>(props: TableProps<T>) => {