DEV Community

Discussion on: React, when to use propTypes what are the best practices?

Collapse
 
floede profile image
Janus Hasseriis

Hi Stefan!

Sorry to necro this old reply :-)

I have a question about using isRequired.
If you have a prop that is required, do you leave it at that, or do you have any other fallbacks?

I'm thinking about:
1) Making sure the code doesn't break even if a required prop is not provided.
and / or
2) Having a part of or the whole component not render at all if the required prop is not provided.

I feel like you can argue that "isRequired" is the fallback.
But on the other hand, it's often nice to avoid breaking the application or having it render weird stuff.

A simple example would be a menu element where you'd probably set a text as required.

Collapse
 
stefandorresteijn profile image
Stefan Dorresteijn

I think it's nice not to break an app, but when a developer is misusing a component, the app should break. Otherwise it can be difficult to debug why the app doesn't work as expected. Check your values before rendering the component, then the component should be very dumb and just require certain props.