DEV Community

Discussion on: Shouldn't recursion be prevented in React component?

Collapse
 
elijahtrillionz profile image
Elijah Trillionz

Totally get this use-case, I have actually made something similar in devRoadMap.vercel.app..

But I just didn't think it would be useful having a recursive component, but now that I think of these components as more of HTML elements in the DOM, I can now see how useful it is.

To prevent recursion in React is to prevent React from working. The reconciler at its heart processes a tree to decide out what needs re-rendering, and it uses recursion to descend through that tree and collect its decisions.

Yeah this is true. My question wasn't really if recursion should be removed from React, because we can't really get it out, I was actually concerned about recursion that I had to do with components within the app.

Thanks a lot for sharing, I can now see things differently