Skip to content

feat: fixes the 310 error that sometimes happens because of a conditional called hook

Walter requested to merge feature/fix-hook-conditionally into master

This change fixes a React “Hook is called conditionally” error (#310) by:

  • Extracting all useSelector calls out of our URL-helper functions and into the top level of the ContextualActionsButtons component.
  • Replacing the old isCurrentUserId helper (which invoked a hook inside a utility) with a pure function that’s created once in the component.
  • Passing that pure isCurrentUserId down into each URL-generator (getNodeUrls, getMediaUrls, etc.), so that hooks are only ever called unconditionally at the component root.

This issue was happening on VWNL corp when loggedIn and watching a node because the useSelector was called conditionally. With this refactor, we comply with the Rules of Hooks and prevent the conditional-hook invocation that was causing React error #310.

Merge request reports

Loading