Fork me on GitHub
#cljsrn
<
2022-02-16
>
Mikko Harju09:02:03

What approaches there are to find out why https://callstack.github.io/react-native-paper/text-input.html this is "flickering" when I do the basic adapt-react-class to it and use re-frame subscription as the value and dispatch the value on-change-text? I've been able to get it to work properly if I use a functional component (reagent 1.1.0 feature) and use local hook state instead of re-frame. So – basically it seems to mount a new component every time instead of reusing the current when the value changes?e

Mikko Harju09:02:02

So just doing

[:> TextInput 
   {:label (t/translate :company-mobile.login/username)
    :value @username
    :onChangeText (fn [t] (re/dispatch [::login/set-username t]))}]
causes the flicker

lepistane09:02:52

yeah basically. I know i had a solution for that let me check

lepistane10:02:06

try to remove the :value if i am not mistaken it should prevent constant re-rendering

Mikko Harju10:02:56

Yeah, that might work but if we want to get the initial value through the subscription that does not work. It has the render prop that can be used to give it a textfield to use – I'll try to use that.

Mikko Harju10:02:22

I think the issue is the same as with web side when using material-ui we need to provide our own input field to it in order for it not to flicker

Mikko Harju10:02:13

OK. I think I solved it 🙂 I just use

(fn [t]
  (re/dispatch-sync (conj dispatch t))
  (r/flush))
And the flickering stops

lepistane11:02:26

removing :value didn't help? great :thumbsup: thanks for sharing solution

Mikko Harju11:02:09

@U45SLGVHV sure, removing :value works but if we want the field to be managed and use the value from the state it can't be removed. If eg. we have an initial value we want there then it's a hassle to get in

Mikko Harju11:02:21

Thanks for your help as well!

👍 1
Michaël Salihi13:02:38

Try with :default-value

hadils19:02:00

Use defaultValue

Mikko Harju05:02:48

Thanks all 🙂 I opted for the dispatch-sync & flush option since the component I'm using does not seem to have a default-value property (at least according to the docs) – and maybe I can provide my own textfield to the game but for now I'll stick to the first option