tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
553 stars 20 forks source link

Generate hook to wrap each route #173

Open eddiesholl opened 9 months ago

eddiesholl commented 9 months ago

We've recently grabbed this library to bring some type safety to a next app with many heavily nested routes. The improvement is awesome.

I'm wondering if there's any thought of extending the code generation to include a hook for each route. It is quite noisy to have to build up a path target from scratch every time, unpacking props from useRouter, and attaching them to a long string that has to be just right. Of course it's much better doing this now with some type safety.

I could have worn I saw a question like this on this repo (or maybe elsewhere) a few weeks back, but couldn't find it again.

Cheers!

tatethurston commented 9 months ago

Hey @eddiesholl I'm happy to consider a PR or a design for this. I've thought about code generation for runtime utilities like this in the past -- the main pieces would be allowing users to opt-in and determining where to place the generated code.

Could you share an example of the route hook you have in mind?

I think the closest question I've seen to something like this is https://github.com/tatethurston/nextjs-routes/issues/39.

eddiesholl commented 9 months ago

Cheers, yes I had read through that one and realised that could factor into something like this. I'll see if I can propose something