-
| Hello, In my application, I need to get the length of the table's  Some things I've tried: const length = tableInstance.current?.filteredRows.length || 0;
 const length = useMemo(() => {
  return tableInstance.current?.filteredRows.length || 0;
}, [tableInstance.current?.filteredRows]);
 const [length, setLength] = useState<number>(0);
useEffect(() => {
  setLength(tableInstance.current?.filteredRows.length || 0);
}, [tableInstance.current?.filteredRows]);
 | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| After some investigation, I found that the issue was in the  const useControlledState = (state: any) => {
  useEffect(() => {
    if (state.filters.length > 0) {
      doSomethingWithFilters(state.filters);
    }
  }, [state.filters]);
  return useMemo(() => state, [state]);
};This caused the  const debounceFilters = useRef(
  debounce((filters: any) => {
    doSomethingWithFilters(filters);
  }, 100)
).current;
const useControlledState = (state: any) => {
  useEffect(() => {
    if (state.filters.length > 0) {
      debounceFilters(state.filters);
    }
    return () => debounceFilters.cancel();
  }, [state.filters]);
  return useMemo(() => state, [state]);
}; | 
Beta Was this translation helpful? Give feedback.
After some investigation, I found that the issue was in the
useControlledStatethat I was passing to thereactTableOptionsprop, that was being triggered due to the dependency that I set in the useEffect:This caused the
doSomethingWithFilters()function to be called everytime the value of a filter was updated, triggering the mentioned React error. To solve this, I've simply added a debounce before calling the function: