I'm currently loading more than 2000 objects from a CSV file in a useEffect hook. Each time searchTerm changes, all data in the CSV file is reloaded and filtered. Refer to the code below for details:
useEffect( () => {
const asyncLoadWords = async () => {
const dnd_words = await d3.csv(data_csv);
const results = dnd_words.filter(wordObject => {
return wordObject.原词.toLowerCase().includes(searchTerm);
});
setSearchResults(results);
}
asyncLoadWords();
},[searchTerm]);
Is there a way to persist the CSV data between renders? One possible solution I've been thinking about is creating a child component that takes the CSV data as a prop and rerenders via useEffect.
Any input would be greatly appreciated.