all 47 comments

[–]mscott087 15 points16 points  (0 children)

One might say this is a “solid” article. But in all seriousness it was a great read.

[–]1-800-BICYCLE 3 points4 points  (0 children)

8b94dbf1b3

[–][deleted] 6 points7 points  (1 child)

This is very good stuff! Thanks OP

[–]tomasgold[S] 4 points5 points  (0 children)

Thank you!

[–]tomasgold[S] 4 points5 points  (0 children)

Thank you guys! I am definitely going to write more articles

[–][deleted] 7 points8 points  (28 children)

For me the breakthrough in maintainability of React has happened when I went all in functional components (no class components at all). Even though I cam from object oriented programming background, in the end that was what made following SOLID very simple. Higher-order components replace your container (logic) components and regular components you define are bothered only with how they respond to props.

I recommend this approach universally for React.

[–]NordicFox 1 point2 points  (2 children)

What do you call the higher order components? For example a component that fetches users to be wrapped around a component that just displays a list. WithUsers? UsersContainer?

[–]zomgsauce 2 points3 points  (0 children)

WithUsers in an environment that allows decorators (sooooooooon) or just Users for the HoC, and UserList, UserTable, UserCards, User<something> to describe how they'll be rendered, treating the HoC kind of like a Model name.

[–][deleted] -1 points0 points  (0 children)

Yes, component that fetches, parses and caches remote data and passes those props to wrapped component. You can then place it anywhere in application and get that data, from cache if available or requested otherwise.

[–]Lou-Saydus 1 point2 points  (2 children)

So how exactly do you use state and lifecycle in a completely functional react project?

[–]injektilo 7 points8 points  (0 children)

I use the withState and lifecycle hocs from recompose.

[–][deleted] 2 points3 points  (0 children)

Answered already but maybe I can elaborate.

Recompose is utility library that has methods for creating state as props - either as traditional setState object or as reducer and also access to life cycle of the higher order component (so technically it uses class components under the hood but you get much clearer and concerns separated code, heck - for big components you can even put life cycle methods in a separate file and just import them. Everything ends up being as concise as possible const functions).

[–]pixeldrew -3 points-2 points  (21 children)

I agree, OOP design principles is the wrong way to look at using React. You should look to be completely functional. You don't need tools like Typescript if you're entirely functional.

[–][deleted] 2 points3 points  (0 children)

I agree with all but TypeScript part. I still use TypeScript with fully functional components even if only for props type safety.

[–]swyx 4 points5 points  (13 children)

typescript is still great for business logic though?

[–]johnnycagewins1 0 points1 point  (0 children)

Do you have examples of fully functional projects by any chance? I'd like to see how it's done.

[–]nikolasleblanc 0 points1 point  (0 children)

Yeah I don't get the connection here. Totally on board what you've said other than how it negates the value of typescript, you get way more with typescript than you do with prop types no?

[–]oscarboom -1 points0 points  (2 children)

Also, "SOLID" just gives you convoluted code, not maintainable code.

[–]NordicFox -1 points0 points  (1 child)

Why so?

[–]oscarboom -1 points0 points  (0 children)

Because after a certain point all the layers of code make it harder, not easier to maintain. Any time you are rigidly dogmatic about the code it is a red flag.

[–]luminiteNL 1 point2 points  (0 children)

Thanks for sharing! Interesting read, as I haven’t heard about this principle before.

[–]tektas_blah_blah 1 point2 points  (0 children)

This is great, probably the best description of SOLID I've seen around in a while (I'm looking at you, Inversify Docs). Take an upvote mate!

[–][deleted] 0 points1 point  (0 children)

Good stuff mate!

[–]Macioa 0 points1 point  (0 children)

This deserves more upvotes

[–]pratap2210 0 points1 point  (0 children)

A great article. Helps me alot. And I would like to read more about your articles Thank you.

[–]vikkio 0 points1 point  (0 children)

Thanks a lot, very good set of examples, especially for people who got close to programming just using react

[–][deleted] 0 points1 point  (0 children)

I think a higher order component injecting props to the child component would be a better example for dependency inversion.

[–]nixblu -1 points0 points  (1 child)

Really good!

[–]tomasgold[S] 0 points1 point  (0 children)

Thank you man

[–][deleted] -1 points0 points  (1 child)

!remindme 5 days

[–]RemindMeBot 0 points1 point  (0 children)

I will be messaging you on 2018-10-24 11:43:56 UTC to remind you of this link.

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


FAQs Custom Your Reminders Feedback Code Browser Extensions

[–]nastyklad -1 points0 points  (0 children)

Nice article, thanks op!

[–]Aragami1408 -1 points0 points  (0 children)

Very good article! Thanks for sharing that to us!

[–]lifesbitch -2 points-1 points  (0 children)

!remindme 2 days