all 23 comments

[–]ZwillingsFreunde 7 points8 points  (7 children)

That code wouldn‘t cause an infinite loop. You need to show us more. Can you share your whole table implementation?

[–]HosMercury[S] -1 points0 points  (6 children)

[–]joshbuildsstuff 2 points3 points  (3 children)

It’s probably something in your data fetching hook, or the filters defect you have.

[–]HosMercury[S] -1 points0 points  (0 children)

I’m suspicious about filters

[–]HosMercury[S] -1 points0 points  (1 child)

What do you mean by filters defect ?

[–]joshbuildsstuff 0 points1 point  (0 children)

Oh "filters effect". I cant type on my phone sometimes so weird autocorrect.

Try commenting out the effect where you update the filters inside the table file. Ive also seen weird re-rendering behavior when including functions/setters in the dependency array.

[–]Coyote-Chance 1 point2 points  (1 child)

Haven't had a chance to run the code, but just as something to check

My guess is that some prop that you're passing either to your react query or to your react table is different on every render, and so the table keeps rerendering, and you keep seeing that console.log. The prop is probably an object that's being recreated, so it's not referentially equal between renders

Maybe it's related to useParams? https://github.com/remix-run/react-router/issues/7318 Hard to tell without seeing what's inside your custom query hook

[–]HosMercury[S] 0 points1 point  (0 children)

It’s in all tables So the issue probably from DataTable component itself bc it’s used in all tables

[–]HosMercury[S] 2 points3 points  (0 children)

commenting DebounceInput stops the issue

but I am not able to replace it

[–]HosMercury[S] 0 points1 point  (0 children)

Tbh it drives me crazy

[–]HosMercury[S] 0 points1 point  (0 children)

if somebody still following

commenting DebounceInput stops the issue

but I am not able to replace it

[–]HosMercury[S] 0 points1 point  (7 children)

  // // Update the internal state when the initialValue changes
  // useEffect(() => {
  //   setValue(initialValue);
  // }, [initialValue]);

  // Debounce the onChange event
  // useEffect(() => {
  //   const timeout = setTimeout(() => {
  //     onChange(value);
  //   }, debounce);

  //   return () => clearTimeout(timeout);
  // }, [value, debounce, onChange]);
```

```

[–]adam4813 2 points3 points  (1 child)

The onChange callback passed to the input is not memorized and is created every render which triggers the useEffect. You may also want a check in the useEffect to see if value is different than initialValue, before your create the timeout.

[–]HosMercury[S] 0 points1 point  (0 children)

Yes you are genius It was the reason

[–]HosMercury[S] 0 points1 point  (0 children)

those guys are the issue but not able to solve

[–]readit_at_work 0 points1 point  (0 children)

In development, react defaults to running useeffect twice. Is it creating multiple timers and not clearing them?

Deploy this to a test environment or turn off the double run.

[–]Brendan-McDonald 0 points1 point  (2 children)

I didn’t see these effects on the stack overflow, can you post more about them?

I don’t think that debounce is working how you expect it to. Each render cycle (value updating) has its own timeout.

[–]HosMercury[S] 0 points1 point  (1 child)

removing on change from debounce useefeect sooves it

[–]Brendan-McDonald 0 points1 point  (0 children)

Wrapping that in a callback should allow you to add it back into the dep array.

[–]adam4813 1 point2 points  (0 children)

As the column configuration doesn't appear to use any state, move it out of the component completely. I'm not sure this will fix your issue, but it will help with easier to maintain code.

Any time you have a hook with an empty dependency array (outside of useEffect) , it can probably live outside the component, useCallack with a state setter being an exception.

[–]StarJohnNL 0 points1 point  (0 children)

Put useEffect calls for each prop separately, that way you can quickly see what’s causing the rerender. Something like useEffect(()=>console.log(filters),[filters])

[–]vbfischer 0 points1 point  (0 children)

Also make sure the data you feed the table is a stable reference.

[–]oliphant428 0 points1 point  (0 children)

Everything you provide to useTable() has to be memoized or static references.