Fork me on GitHub
#reagent
<
2018-02-24
>
roti12:02:50

Hi, I have a problem with a component: if fails to rerender even though I think it should, how can I debug the situation?

gadfly36112:02:18

@roti to help us help you, can you provide more information like a code snippet? A random guess is that you 1) not derefing a reagent atom in the component, or 2) the atom you are derefing is a normal clojurescript atom instead of a reagent atom, or 3) you are creating a reagent atom in the view ... but not doing so in a 'form-2' style and the atom is getting recreated every render

roti12:02:27

my deref is inside a for, is that a problem?

gadfly36112:02:41

Wrap it in a doall

gadfly36112:02:54

for is lazy, so it is possible that is a problem

roti12:02:04

yep, that was the cause

roti12:02:31

i moved the deref in a top let and it works now

roti12:02:45

I guess that reagent doesn't establish the link because at that time the render function is not yet executed

roti12:02:31

thanks for the link

roti13:02:34

how can I trigger e re-render (for the on-load function from figwheel?

roti13:02:47

can I use the normal render method?

mikerod15:02:17

@roti in dev mode I believe reagent typically warns on deref ratoms in a for. It has at least some detection. Just curious if you didn’t have warnings show up.

roti15:02:59

I did not get a warning, but I don't know if I am in dev mode

justinlee15:02:50

@roti if you need to force a reload then calling the reagent/render function again is the best way to do that

roti15:02:10

doesn't seem to work when the rendering function has hanged

roti15:02:05

I probably need to tell reagent to render everything, not only those components whose ratom has changed

justinlee16:02:12

oh sorry, i thought you were manually hooking into some kind of hot reload signal, in which case you would just re-render the top level component in your tree

justinlee16:02:51

(defn mount-root []
  (reagent/render [top-level-component]
    (.getElementById js/document "app")))

roti16:02:13

that's what i'm doing

justinlee16:02:08

yea that will cause a remount. now you may still be experiencing some bugs like the one discussed above where the components do not reflect your data in a way that you expect

justinlee16:02:23

so shopping-list is not going to react to the atom

justinlee16:02:50

so wrap that for in a doall

justinlee16:02:48

next problem: line 10 of the snippet: you have a fn there that you don’t need and that doesn’t repeat the outer arguments. you should probably just remove it and do the destructuring right in the defn declaration

tkircsi16:02:57

Thx justinlee! I’ll check them.

justinlee16:02:18

i am surprised that adding an item updates your components

tkircsi16:02:22

It works now. Thank you! Yes, there is strange it worked for adding a new item or removing one it worked, but for updating one it didn’t.

tkircsi16:02:32

But now It works well. Thx