How is double type checking a good thing?
Hrusikesh Panda

Hi Hrushikesh, I think you’ve misunderstood a little bit.

If an unchecked prop is flagged by your linter in your container component then you’re manipulating it, or using it for calculations of other variables. If a prop passes into your container and you change the value, does it not make sense to check it when you actually use it? Although it bears the same name, this is fundamentally not the same prop that was passed in.

All this is is an optional layer of safety. If you use a prop inside your container but don’t change the value at all, then it is of course perfectly fine not to check it again, however chances are that if your prop is being used within your container then it is being manipulated in some way.

An example might help clear things up a bit:

You have a carousel component and you want a consistent width for all the elements of the carousel. To enable this you allow the developer using your carousel to pass width to be used for all of the elements.

Inside the container of your carousel you will be doing some stuff under-the-hood with the given width prop. Let’s say you’re taking into account some control buttons that will display on the sides of each element. So inside your container you do something like the following:

width = width – (buttonWidth * 2)

That there, however simple, is a chance for the type of width to change. Now, does it not make sense to check this value again when you actually use it?

Show your support

Clapping shows how much you appreciated Josh J’s story.