Bits and bytes of code

Bytes is my collection of short-form posts, tips, and things I learn as I build software.

Showing results for #typescript

Clear

If you use TypeScript, you've more than likely seen keyof typeof obj at one point or another to get a union type representing the keys of the given object. But what if we want to get a subset of the object keys, based on the values in the object?

In a previous Byte, I showed the useStrictParams hook as a way to better manage React router params with better type safety and ease of use. Since then, I've made some improvements and published it to npm!

The useParams and useSearchParams hooks from React Router are critical when working with dynamic routes, however they have some sharp edges when used with TypeScript. With a small amount of additional code, we can make it much easier to work with params.