Search code examples
reactjsclojurescript

How can I convert React code to ClojureScript one?


Here is the code I want to convert into ClojureScript:

<Table
  onRow={(record, rowIndex) => {
    return {
      onClick: (event) => {},
      onDoubleClick: (event) => {},
    };
  }}
....

I need to be able to provide multiple events on Table (onRow) component but could not find a way to convert this code into ClojureScript.


Solution

  • onRow seems expect a "factory" function which returns the actual event handlers.

    (defn on-row-factory [record row-index]
      #js {:onClick (fn [event] ...)
           :onDoubleClick (fn [event] ...)})
    
    ;; reagent
    
    [:> Table {:onRow on-row-factory} ...]
    

    You don't need to use the defn and could just inline a fn instead.