본문 바로가기

React

useEffect useState array sort

반응형

구글 검색 - useeffect usestate array sort

 

https://stackoverflow.com/questions/62993051/sort-the-obj-in-array-by-react-useeffect-method

 

Sort the obj in array By React useEffect method

I only paste a part of my React Code here, I have an array in my State, it can be updated and added the new array from browser. My question is I want that array can be sorted from smallest to great...

stackoverflow.com

 

 

  useEffect(() => {
    const sorted = [...totalList].sort((a, b) => b.time - a.time);

    setSortedList(sorted);
  }, [totalList]);

 

반응형