Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
How put scroll to top when scroller is inside Div in React

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>
    </>
  );
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!