Fork me on GitHub
#helix
<
2023-02-13
>
hifumi12302:02:10

I don’t use Helix, but logout-user will compile to an ordinary JavaScript function. Secondly, your TopBar component uses #(api/logout-user), which is shorthand for (fn [] (api/logout-user)). This means you attempting to use React Hooks within a nested function. That’s likely why you’re getting the error. My best guess to fix your issue is to change your :on-change value to simply api/logout-user

👀 2
👍 2
moliveira03:02:20

Indeed, it's React that won't allow me to call the useNavigation inside any function other than a component definition, so I need to call the hook on the TopBar and pass the return along I guess thanks for the help!

lilactown16:02:41

to be clear: you can call hooks inside of a nested function. these are typically called "Custom hooks", example:

(defn use-counter
  [init]
  (hooks/use-state init))

(defnc my-component
  []
  (let [[counter set-counter] (use-counter)]
    ,,,))

lilactown16:02:46

@tuto.mso the problem with your code is that you were calling the hook inside a function that gets run in response to the user clicking a button. Hooks have to be run on every render of a component.

lilactown16:02:21

like you said, the fix here is to call useLocation inside of TopBar and pass the return value to logout-user

👍 3