I have this function:
const handleSearch = (event) => {
const currentValue = event?.target?.value;
const filteredData = searchTable(currentValue, originalData);
setDataToTable(filteredData);
};
I tried to use useMemo()
to memoize the value of filteredData
in order to not perform the function searchTable
because it's slow. I tried this inside the handleSearch
function:
const filteredData = useMemo(() => searchTable(currentValue, originalData), [currentValue]);
But I get the Hooks can only be called inside of the body of a function component
message which is correct.
How should I use useMemo
for my case?