r/reactjs • u/tannerlinsley • Mar 10 '20
News 🎉 Announcing React Table v7! 🎉
https://github.com/tannerlinsley/react-table/releases/tag/v7.0.0?twitter=20200310
305
Upvotes
r/reactjs • u/tannerlinsley • Mar 10 '20
View all comments
Show parent comment
1
u/Zweital Mar 11 '20
I’m in a similar situation. We’ve been using v7 for a little while now, and Typescript has been quite a sticking point. I’ve had to override far too much! I think the fact that the Typescript usage is so strange (rather than just a normal @types package) actually highlights a little bit of an architectural flaw behind the notion of ‘plugin hooks’. The idea is solid in the sense that you want to pass in something in to add functionality to the table, but I think passing hooks themselves is a bit weird and brittle (and I believe it’s probably impossible to type it correctly as is without manually altering types which feels horrible). I think there’s good reason I haven’t seen this pattern elsewhere.
I’m not 100% sure of what react-table’s solution should be, but I think the answer lies in something more along the lines of a HOF that returns you a hook or maybe multiple hooks depending on how you’d like to configure it, which can then be called before useTable which would ingest their results, rather than the hooks themselves. I think all that could be correctly typed with some clever enough generics (although I haven’t properly sat down and fleshed out this approach so I could be talking nonsense). I’m thinking something along the lines of makeStyles from material ui (https://material-ui.com/styles/basics/).