React stay sane and DRY

If you are in a project with a tight deadline it can become overwhelming and you might want to try to cut corners by creating huge components.

Been there, done that, gotten bitten and the T-Shirt.

For the sake of your sanity (and to comply with DRY (Don´t Repeat Yourself)) I advise you to create smaller (function) components.

It´s fine to at first create a big component to solve your problem. But then iterate at least one more time and try to extract sub components.

Even when you put the sub components into the same file, by extracting them from the big component you make it more manageable and adjustable. By keeping them in the same file you limit the amount of extra work. But you´re potentially able to reuse it later by simple extracting it into it´s own file.

It means a bit of extra work but believe me, especially with multiple developers it can save you hours.

As an example of my experience:

We needed to show the same button on staging and production, just show an alert message on production and block going to the next step. On staging it needed to be bookable.

The other developer and I interfered with each other, until I extracted it into two button components and a deciding component. Since then he only changed the button layout and no more problems.

Let me know if that helped you.

Best,

Frank

Leave a Reply