When to use 'isRequired' in PropTypes

82 Views Asked by At

I understand the benefit of PropTypes, but I'm curious as to when it's a not good idea to use 'isRequired' in React PropTypes. I understand that if isRequired is not passed, then the value that is being passed to the object wont throw a warning if that props is not in use.

I've been working on quite a big project and i don't really see any specific reasons as to why 'isRequired' is given or not. Is it passed when the object using that prop wont function without it? if so, then when is there a case when 'isRequired' is not a good idea?

1

There are 1 best solutions below

0
c.hughes On

isRequired only exists to help other developers understand what parameters are and are not necessary to make the given component's basic functionality possible. So if you have optional parameters, they should NOT have isRequired. I personally don't see a lot of value in using isRequired. If the component wont work without the prop, it will become apparent in testing. Unless there is some tricky case where the component may appear to work without some required prop.