Tell me why the re-rendering on the page does not work after the change in userstate Changes occur after clicking on the page again, and not immediately.
useEffect(() => {
const sortfdb = Datadb.sort((a,b) => b.count - a.count);
console.log(sortfdb)
setDatadb(sortfdb);
console.log(Datadb)
},[Datadb])
I have a field on the page, I will add a number, it writes to useState([]), and when changing the useState, it should sort them. But this is not happening. And it happens only when I add a new number.
useEffect, which catches changes, works, and displays everything in the console as it should, but does not want to change it right away on the page It worked fine in react 17, but not now. I can't figure out what went wrong
Update
I realized my mistake, I had to provide sort as an array
setDatadb(el=>[...el].sort((a,b) => b.count - a.count));
But now it throws an error indefinitely, as rendering is constantly happening
next-dev.js?3515:25 Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.