Skip to content

Instantly share code, notes, and snippets.

@jeaye

jeaye/lag.clj Secret

Created August 31, 2017 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeaye/6ace167c6babc122c47e1e528e673813 to your computer and use it in GitHub Desktop.
Save jeaye/6ace167c6babc122c47e1e528e673813 to your computer and use it in GitHub Desktop.
(defn instant-text-input
[{:keys [format-value on-change-text]}]
(let [this' (atom nil)
input (atom nil)
on-change-text' (fn [new-value]
(.setNativeProps @input
#js {:text (format-value new-value)})
(some-> @this' r/force-update)
(on-change-text new-value))]
(r/create-class
{:display-name "instant-text-input"
:component-did-mount
(fn [this] (reset! this' this))
:component-will-unmount
(fn [] (reset! this' nil))
:reagent-render
(fn [props]
[text-input (assoc props
:ref #(reset! input %)
:on-change-text on-change-text')])})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment