Hey all! I've been posting nearly every day recently, but everyone here is so helpful (especially @pulsar merlin , who has helped me quite a few times, you should give him some karma π !) and I learn a lot whenever I post!
My current issue is that I'd like to get my app to render more selectively. The way it works is I pass in data like the following
const treeData = {
isOpen: true,
id: 'parentId',
children: [
{
value: 'React',
isOpen: true,
id: 'childId'
idPath: 'parentID childId'
},
//and so on, recursively
]
}
and from that data i render a component
function List() {
return <ListItem data={treeData} />
}
which is a recursive component
export default memo(function ListItem(props) {
const [isEnter, setIsEnter] = useState(true);
return (
<Collapse in={isEnter} appear unmountOnExit>
<div className="list-item">
{props.data.value &&
(props.data.path ? (
<Link to={props.data.path}>{props.data.value}</Link>
) : (
props.data.value
))}
{props.data.children && props.data.isOpen && (
<ul>
{props.data.children.map((li) => {
return (
<li
key={nanoid()}
className={`${li.isOpen ? "opened " : ""} ${
li.children && li.children.length > 0 ? "openable" : ""
}`}
onClick={(e) => props.openList(e, li.idPath)}
>
<ListItem data={li} openList={props.openList} />
</li>
);
})}
</ul>
)}
</div>
</Collapse>
);
});
I want each instance of ListItem to only re-render when updated, but they ALL re-render (as does List) with treeData state changes. How can I selectively render ONLY the nested component when the corresponding nested child in the state changes? Thanks!