helix

https://github.com/Lokeh/helix
2020-11-11T00:29:39.143800Z

@lilactown How do you pass parameter to the reducer function besides the action ?

lilactown 2020-11-11T01:34:45.144600Z

i'm not sure what you mean yet. the reducer function signature is:

(fn [state action] ,,,)

lilactown 2020-11-11T01:37:46.147600Z

example:

(defn my-reducer
  [state action]
  (case (:type action)
    :foo (update state :foo inc)
    :bar (update state :bar inc)))

(defnc my-component
  (let [[state dispatch] (hooks/use-reducer my-reducer {:foo 0 :bar 0})]
    (d/div
      (d/div "Foo: " (d/button {:on-click #(dispatch {:type :foo})} (:foo state)))
      (d/div "Bar: " (d/button {:on-click #(dispatch {:type :bar})} (:bar state))))))

đź‘Ť 1
ordnungswidrig 2020-11-11T15:19:07.153200Z

The action can by any value. As in the example a map which can also contain “parameters” besides the “action”.

đź‘Ť 1