Functional components that reference Reusability throw "Too many re-renders" is there's a Reusability.never
rpiaggio opened this issue · 2 comments
I'm not sure if this is a bug, but it surely took us some time to figure out.
Since Reusability
is implemented for functional components by using a counter in a useState
, having a Reusability.never
will cause infinite re-renders if renderWithReuse
or withReuse
are used to render. I suspect this will also be the case in use*WithDeps
hooks.
Basically, this line will be invoked in every render: https://github.com/japgolly/scalajs-react/blob/master/coreGeneric/src/main/scala/japgolly/scalajs/react/hooks/CustomHook.scala#L187.
This is somewhat different behavior than when using Reusability.never
on a class component, where if all dependencies have Reusability.never
then the component will behave the same way as if reusability was not set.
Hey @rpiaggio, thanks for raising and tracking down the cause! Fixed. I'll get a release out tomorrow
Thank you!