I have a search field that adds tags to the left side, which after a certain number of tags added it shows overflow-x. I need that after adding a new tag, it scrolls to the right, showing the last searched tag.
The code I made uses the useRef associated with the parent element, so that after inserting a new tag it calls a function that makes the scroll.
The problem is that for some reason, regardless of the value I put in pixels for the scroll, it always reaches the penultimate element, it never reaches the end.
I believe that when he activates the scroll the last element is not yet ready in the useRef, so the penultimate element would be the last one at the moment, but I still haven't found a way to get around this.
My code: https://codesandbox.io/s/nextjs-10-tailwind-2-0-forked-wergkg?file=/pages/index.js
some predefined tags have already been added so that the overflow is already visible
