In my user's profiles page in React, when clicking on an image, it currently scrolls to that specific image within the entire images page. However, I want it to navigate directly to that image element without scrolling. I want to make this change because it becomes very lag when there are 100 pictures in a user's profile.
Is there any method in react or nextjs to achieve this?
You can create refs for each image and use the scrollIntoView method to bring the selected image into the view. Here's an example using React and Next.js:
1)Assuming you have a list of images in your component:
// ImageList.js
// UserProfile.js
3)In the ImageList component, update the img elements to use the refs:
// ImageList.js