Loading video player...
Dev stuff you should know part 10. Here
is a best practice for React and
TypeScript when passing props to a
component. So you've got a user type
with multiple fields and you pass the
entire object to a component that only
needs the name. This works fine, but
there's a tight coupling problem. You
can only use this component in places
where the entire user object is
available even though it just needs a
name. Most devs fix this by writing a
separate type, but the best practice is
to use TypeScript's pick utility. Now
your props stay in sync with the source
type. If you need more fields later,
just add them. This is clear, precise,
and easy to extend. A clear sign you're
coding like a senior developer.
React and TypeScript best practice