[React Typescript] Generic function component

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>) => {

 

posted @ 2023-08-11 15:01  Zhentiw  阅读(14)  评论(0)    收藏  举报