Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can unnecessary React.Fragment be poor in performance?

Recently, I found that our company's code performance is poor. As I reviewed code, there's so many codes like this:

condition ? <SomeComponent /> : <></>

They use Fragment as replacement of null. Can this code occur performance problem?

like image 729
Doyeong Kim Avatar asked Feb 02 '26 15:02

Doyeong Kim


1 Answers

It's unlikely that the fragments are causing (if any) noticeable performance issues. As this answer highlights, fragments don't actually create an extra DOM node.

With that said, the react docs do suggest using null when you don't want a component to render at all, but again I don't think using them would be the root cause of any slowness in your app.

I'd look at potential unnecessary re-renders, especially in nested child components being re-rendered by parent components with state changes happening.

I'd also definitely a look at the React Profiler and use it to get a sense of what's causing any performance issues.

like image 53
adrian Avatar answered Feb 04 '26 03:02

adrian