DEV Community

Discussion on: Stop returning NULL components

Collapse
 
loopmode profile image
Jovica Aleksic

Interesting. Besides the point of the author tho. He argues we shouldn't do that either - because the component will still go through lifecycle before returning empty fragment. I'd love to know perf difference to returning null tho. My feeling is that it must be. But slower tho.

Collapse
 
ivan_jrmc profile image
Ivan Jeremic • Edited

I'n not sure if Fragment also triggers a full lifecycle would be interesting to look into this a bit more.

Thread Thread
 
loopmode profile image
Jovica Aleksic

I guess so. In the end, render is performed and returns something. And execution of the render is part of the lifecycle.
The point is that react must first evaluate the empty fragment to figure out "it's nothing" as opposed it was filled with children.

Thread Thread
 
ivan_jrmc profile image
Ivan Jeremic

Yeah thinking more about it that makes sense. Need to go back and optimize 😫

Thread Thread
 
ucvdesh profile image
Daniel Silva

Yeah bro, a empty fragment also trigger a full lifecycle because of the render of the fragment, as soon as you have it, then the component exist ergo, have its own lifecycle