Closed twall closed 6 months ago
The registerEvents
should be used in a useEffect
like in this example: https://github.com/sim51/react-sigma/blob/main/project/packages/examples/src/views/events.tsx
If you want to use it directly in your component, you must use the useMemo
hook for the settings, to avoid the change th ref of the object.
This is the expected behavior, which respect the react way.
You should probably update the docs at https://sim51.github.io/react-sigma/docs/api/core/#useregisterevents to reflect that usage.
On Tue, Apr 2, 2024 at 10:18 AM Benoit Simard @.***> wrote:
The registerEvents should be used in a useEffect like in this example: https://github.com/sim51/react-sigma/blob/main/project/packages/examples/src/views/events.tsx
If you want to use it directly in your component, you must use the useMemo hook for the settings, to avoid the change th ref of the object.
This is the expected behavior, which respect the react way.
— Reply to this email directly, view it on GitHub https://github.com/sim51/react-sigma/issues/63#issuecomment-2032170594, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFYZLOJMKBH6TUIMHWWYKLY3K4ZZAVCNFSM6AAAAABFNISHTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZSGE3TANJZGQ . You are receiving this because you authored the thread.Message ID: @.***>
Agree, this code comment (which is used to generate this doc) should be changed.
Thanks for the clarification.
TS doc has been updated, and so the doc on the website
useRegisterEvents
if used as in the hooks example triggers endless re-renders. it must be put within auseEffect
function to prevent re-renders.Expected behavior Events should be registered, and deregistered when the component is unmounted. I should be able to call
registerEvents
without having to memoize the object passed in. It should probably be doing a deep compare of its argument.Actual behavior
useRegisterEvents
returns its useState setter function, and usesuseEffect
with a dependency of the object passed toregisterEvents
. This means that theuseEffect
function's argument will be run on every call toMyComponent
, since the object passed in has a different identity.