Home > Software design >  React ref current scrollLeft not updating
React ref current scrollLeft not updating

Time:09-17

Can someone explain why this code returns the same value in the two logs?

Visually the change is applied.

console.log(refer.current.scrollLeft);
refer.current.scrollLeft  = scrollOffset;
console.log(refer.current.scrollLeft);

CodePudding user response:

If the element the ref is attached to has scrollBehavior: smooth applied to it then the value doesn't update instantaneously.

  • Related