As you can see in the image the scroller is in the middle. Now when goes to an organization I want the scroller to go up to its start position.
const scrollToRef = (ref) => window.scrollTo(0, ref.current.offsetTop);
const ListItemScroll = (props) => {
let {
resultList,
indexChange,
radioValue,
radioHandleChange,
setParamsInc,
searchText,
loading,
noRecords
} = props;
const listInnerRef = useRef();
const onScroll = () => {
if (searchText.length === 0) {
if (listInnerRef.current) {
const { scrollTop, scrollHeight, clientHeight } = listInnerRef.current;
if (scrollTop + clientHeight === scrollHeight) {
setParamsInc((prev) => prev + 1);
}
}
}
};
This is what I am trying to do but it doesn't work
const executeScroll = () => scrollToRef(listInnerRef);
useEffect(() => {
console.log("scroll");
executeScroll();
}, [indexChange]);
return (
<>
<div
onScroll={onScroll}
ref={listInnerRef}
style={{ overflow: "auto", overflowX: "hidden", height: "100%" }}
>
List of filter values
</div>
</>
);
};
