-1

I'm trying to build a simple webapp that will have a list of patients, displaying their vital signals values (such as heart rate, spo2 levels, etc...): Im using react for the frontend and Im trying to use setInterval to update said values periodically. However Im having some trouble with that, the list of patients in state is updated, but the new values are not displaying.

Here's the code

I already tried something similar, just like below and this one works fine, so im really clueless about what the problem might be: example

Edit: I can see that the state is updated in the console.log, I just cant get those values to be displayed on the screen each second

  • 8
    Welcome to Stack Overflow! Please take the [tour], have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Please post code, error messages, markup, and other textual information **as text**, not as a *picture* of text. Why: http://meta.stackoverflow.com/q/285551/157247 – T.J. Crowder Aug 07 '21 at 12:12
  • 1
    Please also search thoroughly before posting ([example](/search?q=%5Breactjs%5D+state+not+updating), [example](https://duckduckgo.com/?q=react+state+not+updating+site%3Astackoverflow.com)). SO has a **huge** number of answered questions about React state not updating, one or many of which probably relate to your problem. – T.J. Crowder Aug 07 '21 at 12:14

1 Answers1

0

As you are getting patients details from api already you can directly update state like this, no need to maintain separate array for that.

.then(res=>{
  this.setState({patients: res.data.patient})
})
Amruth
  • 5,792
  • 2
  • 28
  • 41