DEV Community

Cover image for Mastering S.O.L.I.D Principles in React: Easy Examples and Best Practices

Mastering S.O.L.I.D Principles in React: Easy Examples and Best Practices

drruvari on May 10, 2024

Single Responsibility Principle (SRP) A component should have only one reason to change, meaning it should have only one job. ...
Collapse
 
gitkearney profile image
Kearney Taaffe

As someone who came from a SOLID background (PHP) and started functional programming using React this article did an awesome job without trying to shoehorn JavaScript classes into React's functional style.

Love the examples of do vs don't. They were easy to follow, simple, and made sense. Good job

Collapse
 
drruvari profile image
drruvari

Hi Kearney, thanks so much for your kind words! I’m really glad to hear that the examples were clear and helpful for you. If there's any other topic you'd like to see covered in this style, let me know!

Collapse
 
abi0l9 profile image
Monsur Oyedeji

Looking at this principles, I can boldly say that I have learnt the conventional ways of writing codes from Open University of Helsinki. Although, I never knew they had names but we were taught all these.

Thanks for this piece of information πŸ™‚

Collapse
 
drruvari profile image
drruvari

That’s fantastic, Monsur! It's great to hear about your experiences with the Open University of Helsinki.

Collapse
 
tassiofront profile image
TΓ‘ssio

Pretty nice article! πŸ‘πŸš€ I created one regarding unit test and the component used as example was created using both SRP and OCP principles. I even said that in my article too.

Unit Testing: A Hands-On Guide with Real Examples - React + Vitest (p.1)

Collapse
 
drruvari profile image
drruvari

Amazing stuff!

Collapse
 
fatjona profile image
fatjona

Thank you very much. This help me so much!

Collapse
 
drruvari profile image
drruvari

You're welcome.

Collapse
 
hasanbisha profile image
hasanbisha

sensational

Collapse
 
drruvari profile image
drruvari

hehe

Collapse
 
robertheory profile image
Roberto Costa

I really loved your article, I myself like the idea of applying SOLID in ReactJS and I have an article about it, congratulations on the great initiative and sharing of knowledge <3

Collapse
 
drruvari profile image
drruvari

Thank you so much for your kind words and for sharing your enthusiasm for applying SOLID principles in ReactJS.

Collapse
 
kibaekkimm profile image
Kibaek Kim

Good explanation and example code.
Thank you!

Collapse
 
drruvari profile image
drruvari

I'm glad you found the information helpful!

Collapse
 
otarampinelli profile image
Otavio Rampinelli

Great examples

Collapse
 
drruvari profile image
drruvari

Thank you, Otavio! I put a lot of thought into those examples, so I’m really glad they resonated with you.

Collapse
 
vjnvisakh profile image
Visakh Vijayan

nice read

Collapse
 
drruvari profile image
drruvari

Thanks Visakh!

Collapse
 
jitendrachoudhary profile image
Jitendra Choudhary

Awesome article

Collapse
 
drruvari profile image
drruvari

Thanks, Jitendra.

Collapse
 
dugu007 profile image
dpd007

It's very helpful. ThanksπŸ‘πŸ»

Collapse
 
drruvari profile image
drruvari

You're welcome! I’m so glad you found the article helpful.

Collapse
 
andersonlimahw profile image
Anderson Lima

Amazing post!!

Collapse
 
drruvari profile image
drruvari

Thanks, Anderson! I appreciate your feedback.

Collapse
 
armandomuco profile image
armandomuco

that is awesome!

Collapse
 
drruvari profile image
drruvari

thank you!!

Collapse
 
arian94 profile image
Arian94

In ISP, the Text Component should extend let's say the H1 tag; ie. ComponentWithoutProps<'h1'>.

This will not force you to use unnecessary properties and it also follows the rule of OCP.

Collapse
 
drruvari profile image
drruvari

Hi Arian, that's an interesting take on ISP! Extending the H1 tag like that can indeed simplify component interfaces. Thanks for sharing this tip!

Collapse
 
deepakhce profile image
deepak-hce

Simple explanation and very powerful !!

Collapse
 
drruvari profile image
drruvari

Thank you, Deepak! I'm glad you found the explanation simple yet impactful. It's always great to hear that the content is hitting the right notes.

Collapse
 
arlind profile image
Arlind

nice

Collapse
 
drruvari profile image
drruvari

thanks

Collapse
 
xorscode profile image
Joshua Hollis

Not even a casual mention of Uncle Bob Martin. Shameful.

Collapse
 
drruvari profile image
drruvari

Hi Joshua, you make a fair point. Uncle Bob Martin's work has been foundational in the software development world. Thanks for your feedback! :')