Call twice setUsers when create data? I don't get it

On the create data lecture from connecting to backend session, setUsers is called twice, first to render de UI then when the api is called ??? the first time the “users” array from useState() is modified with the new object {id:0, name:‘Mosh’} why the second time the ‘users’ array modify this object instead adding new object from api {id:1, name:‘Mosh’}

Hi @Jorge,

After posting my question, I just saw your post and we have the same question

:slight_smile: /\

I found an answer on another forum…that says that all callling are part the same render…so the ‘users’ has the same data, the first setUsers() make the cnanges ‘visible’ or ‘effective’ (due a closure feature of js???) after render, but there are a second setUser() that ‘replace’ or ‘cancel’ the first setUser()…sounds logical, but I still looking for more info.

Hi @Jorge

Please see the code that I put some console.log() in it.

here’s the link : About Pure component, why count variable is not resetting to 0? - #11 by herrifransisca