helix

https://github.com/Lokeh/helix
fsd 2021-01-05T20:18:33.266900Z

Hi there, I am working on a frontend application which involves Helix and I needed help it has this in the ns

[helix.hooks :as hooks]
(let [ [show-items] (hooks/use-state false)]) I have a navbar which has button, on click it suppose to invert this show-items. if show-item is false, :onclick it will be true;
{:onclick #(not show-items)}
it gives me an error saying that Uncaught Type-error show_item. call is not a function. My goal is to when I click on the button it changes that state and shows of all the items.

Derek Passen 2021-01-05T20:22:41.269500Z

you need to use the setter-fn

Derek Passen 2021-01-05T20:22:47.270Z

the hook returns the wrapped value and a setter

🙌 1
Emmanuel John 2021-01-05T20:23:28.270800Z

show-items is not a function but the state. I think you want

(let [[visible set-visible] (hooks/use-state false)])
And then:
{:onclick #(set-visible not)}
To toggle it I think

🙌 1
lilactown 2021-01-05T20:24:51.271Z

#(set-visible not) I think is what they want

Emmanuel John 2021-01-05T20:26:42.271400Z

Right. corrected. See https://github.com/lilactown/helix/blob/master/docs/hooks.md#maintaining-state and https://reactjs.org/docs/hooks-state.html for more examples.

fsd 2021-01-05T20:32:05.273300Z

Thanks guys for your quick response I was able to get it working using

(let [[visible set-visible] (hooks/use-state false)])
#(set-visible not)  I appreciate the help! 🙌:skin-tone-2:

👍 1