Kalinovsky Konstantin
Kalinovsky Konstantin

Reputation: 43

Does React component as a single variable renders faster than memoized component?

Trying to understand, if simple react component without any props, that has been created as

const x = <div />

will be rendered in a more efficient way during tree comparison than memorized component?

const y = React.memo(<div />)

Upvotes: 2

Views: 63

Answers (1)

kind user
kind user

Reputation: 41893

will be rendered in a more efficient way during tree comparison than memorized component?

There's no one good answer to that, because it depends on the case. If a component does not include any heavy logic, it's pointless to wrap it with memo because wrapping with memo uses memory and slows down your performance a bit.

In your particular example that you have shown in codesandbox, there's clearly no point to wrap your component with memo since there is not any complex logic inside.

And once again - in your particular case memo is pointless and will run slower than the component without memo (because the built-in shallow comparison of props has to take place). However, the differences in performance will be practically unnoticeable.

Upvotes: 1

Related Questions