Remove flashing on initializing datatable with filter

Summary:
When filter is applied for the first time we shouldn't debounce to avoid "flashing" on datatable loading when it is first loaded without filter and then filter applied after 250ms.

Changelog:
Fixed flashing on opening datatable-based plugin with a filter.

Reviewed By: timur-valiev

Differential Revision: D36602929

fbshipit-source-id: 8bd33f50c92036f2a5565f636f4f2fbe69d900f2
This commit is contained in:
Anton Nikolaev
2022-05-24 04:51:19 -07:00
committed by Facebook GitHub Bot
parent 8d07b7b644
commit 015be5ad83

View File

@@ -339,11 +339,21 @@ export function DataTable<T extends object>(
});
useEffect(
function updateFilter() {
debouncedSetFilter(
tableState.searchValue,
tableState.useRegex,
tableState.columns,
);
if (!dataSource.view.isFiltered) {
dataSource.view.setFilter(
computeDataTableFilter(
tableState.searchValue,
tableState.useRegex,
tableState.columns,
),
);
} else {
debouncedSetFilter(
tableState.searchValue,
tableState.useRegex,
tableState.columns,
);
}
},
// Important dep optimization: we don't want to recalc filters if just the width or visibility changes!
// We pass entire state.columns to computeDataTableFilter, but only changes in the filter are a valid cause to compute a new filter function