ReactJS – Reactivity: Rendering in the list of sizes, having obvious delay

When navigating to a route with 250 duplicate components, I encountered a delay in react and react routers.
I used chrome to analyze and found that the bottleneck was “ReactCompositeComponentMixin.mountComponent “.
The function itself takes 36.1ms, a total of 570.7ms.

I noticed that accessing the route in react-router will cause the assigned routehandler component (which contains these 250 duplicates) The component) is reinitialized every time.
In this case, the state object of this routehandler component is Immutable, but I cannot take advantage of it because shouldComponentUpdate will never be triggered.

I want to know if this is a reaction to know the problem.
If it is, then I will try to render a limited record on initial load and load the rest when the user scrolls down.

All components are “pure” and do not perform complex calculations.

The html structure of the repeated components is as follows:


TESTTEST


TEST



TEST





Due to this performance issue when rendering the list, my intuition is to consider the keys

Do you see a warning when rendering the application?

I recommend adding a unique key attribute for each repeated structure.

The easiest but not the best way is to add an index

arrayOfData.map ((data,index)=>< RepeatedComponent key = (index) />)

Although this will assign a unique value to each key, this method has problems.

The best way is to use id as part of the data, maybe a unique identifier, you would use it like this

arrayOfData.map(data =>< RepeatedComponent key = (data.id) />)< /p>

This will create the burden of id and ensure its uniqueness, but this is the best way.

When navigating to have 250 duplicates When routing components, I encountered delays in reacting and reacting routers.
I used chrome to analyze and found that the bottleneck was “ReactCompositeComponentMixin.mountComponent”.
The function itself took 36.1ms, a total of 570.7ms.

I noticed that accessing the route in react-router causes the assigned routehandler component (which contains these 250 duplicate components) to be reinitialized every time.
In this case, The state object of this routehandler component is Immutable, but I can’t take advantage of it because shouldComponentUpdate will never be triggered.

I want to know if this is a reaction that knows the problem.
If it is, Then I will try to render limited records on initial load and load the rest when the user scrolls down.

All components are “pure” and do not perform complex calculations.

p>

The html structure of the repeating component is as follows:


TESTTEST


TEST



< footer data-reactid=".0.3.0.$3553.2">TEST




Due to this performance when rendering the list The question, my instinct is to consider keys

Do you see a warning when rendering the application?

I suggest adding a unique key attribute for each repeated structure.

The easiest but not the best way is to add an index

arrayOfData.map ((data,index)=>< RepeatedComponent key = (index) />)

Although this will assign a unique value to each key, this method has problems.

The best way is to use id as part of the data, maybe a unique identifier, you would use it like this

arrayOfData.map(data =>< RepeatedComponent key = (data.id) />)< /p>

This will create the burden of id and ensure its uniqueness, but this is the best way.

Leave a Comment

Your email address will not be published.