To use PropTypes in React or not

We’ve developed a simple rule of thumb to follow on this question;

“Don’t. Use. Bloody. PropTypes. They’re just annoying.”

Why do people use PropTypes?

One way to catch and debug errors in your software as you develop is the use of typed programming. JavaScript didn’t used to have that and that was thought of as a bad thing. So when coders came to JavaScript from ‘proper’ programming languages which did enforce strict typing they brought their shit idea with them. They probably thought it would make JavaScript better.

It doesn’t. If you want a typed language for some reason, use typescript. There’s a time & a place for PropTypes. The time is in the past and the place is in the bin.

Why NOT to use them?

They cause crashing errors all the damn time, bloat your code and generally put barriers in the way of clarity and efficiency. If PropTypes are helping you, you should look at how you’re developing.

Learn more about what PropType means from the horses mouth (reactjs.org)

February 1, 2019 10:39 pm
Tags: