How close should a hook be to its usage? - podcast episode cover

How close should a hook be to its usage?

Jan 12, 20233 minSeason 3Ep. 22
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

Transcript: Key Kent! Big fan since I started learning React many moons ago! My name is Asier and I hope you're having a good day. My question is about React custom hooks and your opinion on the following. Imagine there is one parent component in charge of rendering two children components. This parent component is using a custom hook to retrieve some relevant data, let's say that it receives the user name and the date of birth for instance. The first child component requires a prop for the user name and another for the date of birth; and the second child requires another prop but only for the date of birth. My assumption was always to use the hook as close as possible to its usage, in this case, within both children components and not in the parent component. What should be the more readable choice between using the hook just once in the parent component and drilling the props downwards to the children, as opposed to using the hook in each individual hook?

Thanks!

How close should a hook be to its usage?

For the best experience, listen in Metacast app for iOS or Android