Fetching & Displaying Data

What is the best practice for handling race conditions when fetching data?
let currentRequestId = 0;

async function fetchData(query) {
  const requestId = ++currentRequestId;
  
  const response = await fetch(`/api/search?q=${query}`);
  const data = await response.json();
  
  if (requestId === currentRequestId) {
    displayResults(data);
  }
}
Next Question (5/20)