React basic - Connecting to Backend

Hi! I encountered a bug in my code after I finished coding along the Connecting to Backend section. Everything seems fine, but for some reason, when I click “ADD” button, new LI appears and disappears after 1 second leavin’ blank module with buttons. After I click “UPDATE” button it shows “undefined!”. Console shows nothing and network page also shows only update request and nothing more.
Anyone else having this weird behaviour?

I didn’t have this issue. Is it adding an item with no name but it has the buttons? Is there a name passed in the add function?

Image I sent is state after clicking Add button.
Yes, in newUser const there are two parameters - id:0, name: “Tomas Novak”.
How can I send here code snippet?
It looks like it renders new Name on my local machine and after it rerenders empty block with buttons. But it has 0 errors anywhere :smiley:

Can you see if the post to the server succeeds in the network tab?

after reload - in strict mode, one of the renders shows status (canceled), other one is 200.
if I try to update other user tabs, works flawlessly. Adding me with button shows no problem also, but I still disappear after like 0.3 secs.

it’s unfortunate, that I can’t compare to cloned repo for this course part :confused: So I have to go through multiple videos and find my mistake. I think I missed something in creating http-services and so on.

So its like the UI updates and then gets wiped. This is what happens when the patch command fails, eg the users gets reset back to what it was before the update - but you can see that the patch command succeeded… and I guess you can see Tomas added into the data object with id 11? I would also double-check all the places where you setUser and see what you are setting it to.

I think I F’d up on some step with transfering code from App to other components and deleted something that I can’t find right now. Unfortunately, I wasn’t committing this to github so I’ll take it from top and find it down the road :confused:
truth is, that I can see only ID:11 sent to server. but name is in the new user object too.

This is what I get when I send the patch request, so if you have no name on yours I guess the problem lies somewhere in the call to the api as you say…then it would make sense that the line remains with the buttons but no name.

yeah, I get only ID there. detective mode on. thanks :wink:

ok so this is really funny :smiley:
I switched up parameters in setUsers, so newUser was stated but rewritten by spread users from before. Nice mistake there Tomas. fml
setUsers([newUser, …users]);

Edit: I tried to switch it back and forth and app works both ways. So it repaired itself overnight I guess?

Hi Tomas - thanks for the update :smiley: bet you are glad it is fixed and you can move on.