I have an URL where some data is stored, like
[
{"id":1,"first_name":"add","last_name":"add"},
{"id":2,"first_name":"sfdf","last_name":"aad"}
]
etc. I want to sort it by last name and display already sorted array in React functional component. How can I achieve this?
UPD. I have a problem with transforming data from url to an accessible js array, not with sort it
this is how I fetched data from URL
function App() {
const [contacts, setContacts] = useState([]);
const fetchContactsList = async() => {
try {
let response = await fetch(URL)
let contacts = await response.json()
setContacts(contacts)
} catch (error) {
console.log(error)
}
}
useEffect(() => {
fetchContactsList()
}, [])
return (
<main>
<Container>
<Header />
<Search />
<ContactsList contacts={contacts} />
</Container>
</main>
);
}