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
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!
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)]
,,,))
@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.
like you said, the fix here is to call useLocation inside of TopBar and pass the return value to logout-user