question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add plugin to optimise rerender of arrays/objects when keys are added/removed

See original GitHub issue

Hi,

first of all thanks for this awesome library!

I intend to use this with a pretty big nested array. Updating an existing element only triggers re-renders on this element and it’s children. Nice! But when adding a new element all the sibling elements are re-rendering even though they did not change. This can also be seen in the demo for complex tree structure. I looked into the mutate plugin but it doesn’t seem to get me where I want to go either.

Is there a way to only trigger re-renders for the one element that gets added, or for the element that gets removed and it’s the following siblings? Can nested.map somehow be memoized?

Edit: Looks like I just found the solution. Using reacts own memo function seems to do the trick. If anybody is interested I can create a small example. If not this question can be removed

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
avkonstcommented, May 12, 2020

What you are doing does not scale very well. Hookstate does the job (figuring out if it should rerender or not) on any state update for EACH hook placed. You are placing a hook for each element in the arrays. This is not the same as scoped state hooks. scoped state hooks scale to arrays with millions of elements (I checked it). I will keep this ticket as a reference to come up with the prlugin mentioned above, but it will take a while as there are other more important tasks at this stage.

1reaction
avkonstcommented, May 7, 2020

If you sibling component is wrapped by React.memo full array rendering is still taking place, it just becomes quicker for sibling components. You need to be careful: the second parameter for memo function should be proper chain of properties being compared. If your array is array of strings, it is fine. If it is an array of objects, you might need to do equality check of it’s properties which are used inside of the memoized component. You can not pass StateLink variable to the second argument of memo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React re renders all items in array when new items are added ...
javascript - React re renders all items in array when new items are added despite using unique keys for all items - Stack...
Read more >
21 Performance Optimization Techniques for React Apps
Minimize the number of costly DOM operations required to update the React UI with these 21 optimization techniques.
Read more >
Optimizing Performance - React
This technique only renders a small subset of your rows at any given time, and can dramatically reduce the time it takes to...
Read more >
How To Debug React Components Using React Developer ...
In this step, you'll use the React Developer Tools profiler to track component rendering and re-rendering as you use the sample application. You ......
Read more >
How to stop re-rendering lists in React? - Alex Sidorenko
Components always re-render ... First, let's simplify our example by removing all props from the Item . We will still update the parent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found