Jaime Suncin
Jaime Suncin

Reputation: 361

Which would be better? One big stateless component vs Multiple little staless components

In terms of React performance which would be better alternative, use a single big stateless components or split in multiple statless components. By example I have a Post component to render a single post that won't change and it have some parts (title, cover, body).

Example

Please explain your answer, in an easy way.

Upvotes: 2

Views: 1488

Answers (3)

Yossi
Yossi

Reputation: 6027

Regarding the performance: the lightweight components are better since render will be done only for the component that changed, not the entire left side's Post.

I also agree with @Kerry Gougeon comment about reuse and maintenance. Forget about the slight performance difference, implementing the left side is bad for maintenance, it is much easier to test the lightweight components: when you have a problem it will be much faster to find it. Read this: https://reactjs.org/docs/thinking-in-react.html.

Upvotes: 1

Max Millington
Max Millington

Reputation: 4498

Small components hands down.

First and foremost, they are easier to test. Secondly, they are easier to reuse. Thirdly, it is good to get in the mindset that components are very lightweight. This is one of the main points of React. Small lightweight reusable components.

Upvotes: 1

Mubi
Mubi

Reputation: 169

Well These are the reasons according to me :

  • Small Components are easier to understand, test, and maintain
  • You can reuse small components in other different functional components
  • Each individual component can keep its specific logic isolated from other components.

This is a great article if you want to understand more in detail

Upvotes: 4

Related Questions