-
-
Save jeaye/6ace167c6babc122c47e1e528e673813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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