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 greatest on the time values and output to console.log, when the array was updated, how can I make it sort correctly by useEffect method?
The array structure is like the following code, the other part just control the UI updating I haven’t post there because those parts do not affect that sorting function.
const [rows, setRows] = useState([
{time: 3, msg:”there is the first msg”},
{time: 6, msg:”2nd msg”},
{time:11, msg:”do you have any question?”}
]);