Fork me on GitHub
#reagent
<
2023-05-08
>
Michelle Lim13:05:17

is there a way to prevent a component from rerendering when the parent component updates?

eval-on-point14:05:30

Do you want the parent to re-render, or do you actually want only some of the descendants of the parent to re-render?

Michelle Lim14:05:30

the parent receives new data, that only one child needs, and the other child is a hover element that should retain its open state

eval-on-point15:05:16

Awesome, then you can rewrite your component so that neither the parent nor the hover element re-render. Only the child that needs the state should rerender. Have you seen this guide? [reagent/WhenDoComponentsUpdate.md at master · reagent-project/reagent · GitHub](https://github.com/reagent-project/reagent/blob/master/doc/WhenDoComponentsUpdate.md) It probably has what you need.

Michelle Lim15:05:12

that makes sense. my problem is that the parent is a sortable table with data updating in real-time. to sort the rows by attribute, the table needs to be aware of each row's data. it subscribes to a list of data which is mapped over to render each row. but this data updates every few seconds, which causes the entire table to rerender

Michelle Lim15:05:42

each row has an element that opens a preview modal on hover, and that's what i want to prevent repainting

eval-on-point16:05:16

Ah, I see the issue now. I'm no frontend guru so there is probably a better solution, but I would probably decouple the lifecycle of the modal from the table. Have the table push new state to the app-db on hovers and just make the modal reflect that state

lsenjov01:05:23

Are you using unique keys on each row of your table?

Michelle Lim20:05:09

thanks for your thoughts! i made it work by only referencing the real-time data in two specific places — the element that displays it, and the sort handler — instead of passing it to the overall table. so the sort handler updates the table order on demand, instead of the table re-ordering itself whenever data changes. we decided we're ok with the rows not re-ordering in real time