score:0

your code seems to work. the reason why you don't see the change with a console.log is that setstate is asynchronous. this function doesn't update the value, it tells react you want to update it, and react will do it by itself very soon after. the consequence is that the state is not reassigned immediately, and your code logs the state before it is updated.

however you can pass a callback as second argument to setstate which will be called right after the update is done: setstate(newvalue, callback).

setblog({...blog,
      id: foundblog.id,
      title: foundblog.title,
      content: foundblog.content,
      description: foundblog.description,
      publisher: foundblog.publisher,
      published: foundblog.published
}, () => console.log("blog", blog)); // this is called after the state
                                     // is effectively updated

Related Query

More Query from same tag