I'm creating a react application that displays a list of elements on the screen. I created function that lets the user sort the elements by their name.
const [schools, setSchools] = useState([{title: element1}, {title: element2}, ...]);
const sortSchools = (key, value) => {
setSchools(schools.sort(compareValues(key, value)));
console.log(schools);
}
The function is working properly, changing the schools' state; I can see that from the console, but the elements are not re-rendering.
I think this is because React doesn't re-render components when the value hasn't changed, but can't figure out a way to re-render the elements since the order changed.