helix

hifumi123 2023-02-13T02:09:10.022449Z

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

👍 1
👀 1
moliveira 2023-02-13T03:35:20.824989Z

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!

lilactown 2023-02-13T16:26:41.758739Z

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)]
    ,,,))

lilactown 2023-02-13T16:27:46.333789Z

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

lilactown 2023-02-13T16:28:21.920059Z

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

👍 2