Re:Understanding UseMemo and UseCallback
by acover on Wednesday August 31, 2022 @11:57AM
(#32664008)
So in Django templates I'd just flip a style - display from hidden to block of a single div. This would reveal a collapsed section of the tree and I could scroll to the correct div id. (saying list was a bad simplification)
In react because the state flowed from top to bottom I have to be very careful about what objects I update. Just passing down a single reveal could force the virtual dom to update for (num children per node)*depth. Even this required care on what props got updated.
The solutions seemed to be: 1. lots of useMemo so only a minimal amount of a node got recalculated; 2. Directly call a set state function of another child.
Both are quite ugly :( but the second seems nicer as it never could force a full update. However, it seemed to require a registry of set state functions {id: setState}.
If so... can the entire list be stored in state (and updated as necessary), but only the ones marked "is visible" actually get rendered?
Maybe I'm misunderstanding completely...