sim51 / react-sigma

Sigma React component
https://sim51.github.io/react-sigma/
MIT License
172 stars 27 forks source link

useRegisterEvents triggers re-renders #63

Closed twall closed 6 months ago

twall commented 6 months ago

useRegisterEvents if used as in the hooks example triggers endless re-renders. it must be put within a useEffect function to prevent re-renders.

const MyComponent = (props) => {
  const registerEvents = useRegisterEvents();
  registerEvents({});
  ...
  return <div />;
};
sim51 commented 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.

twall commented 6 months ago

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: @.***>

sim51 commented 6 months ago

Agree, this code comment (which is used to generate this doc) should be changed.

twall commented 6 months ago

Thanks for the clarification.

sim51 commented 6 months ago

TS doc has been updated, and so the doc on the website