10

While using react inline-style most people what they do is use object in styles attribute. for eg. <div style={{left: '54px', position: 'absolute'}}> </div>

Does this react diff algorithm fails over here as their is new object created everytime it re-renders.

Priyank Bhatt
  • 604
  • 4
  • 15

1 Answers1

2

YES, It will affect the diff algorithm

Like you said you are creating an Object every time when you re-render.

But, when you do the following

const style = {left: '54px', position: 'absolute'}

<div style={style}></div>

you're passing a reference of style which remains the same throughout the component's lifecycle.

This is same for arrow functions. Read more about this here

Community
  • 1
  • 1
Pranesh Ravi
  • 18,642
  • 9
  • 46
  • 70