Generics in Class Components
Class components still exist in legacy codebases, and it's important to understand how to convert them to be generic.
Here we have another Table
component, but this time it's a class component:
interface TableProps { rows: any[]; renderRow: (row: any) => ReactNode;}export cl
Transcript
00:00 In this exercise, we're going to work with exactly the same component as we've seen before, this table, which has exactly the same behavior. In fact, we're starting from exactly the same point, except it's not a functional component anymore, it's a class. So there are still class components knocking around in legacy codebases, and it's important to understand how to turn it into
00:19 a generic class because classes can be generic too. So here we've got our table class extending React.Component, which is the classic way to do this, and we pass in table props here as the props for our React components. So down here, we're having exactly the same issues as we had before.
00:38 What we need to do is to basically try to find a way to make table generic and to pass in T row into table props and do exactly the same thing as we had before. So good luck.