I am trying to have a table update in a react application but it doesn’t update when the variable that it depends on changes, this is where I create the state, It is an array of objects.
const [leaderboard, setLeaderboard] = useState([]);
This is how I alter it:
setLeaderboard(rankings)
This is the table section within my return
<table>
<tbody>
<tr>
<th>Rank</th>
<th>Name</th>
<th>Stars</th>
<th>Percentage</th>
</tr>
{leaderboard.map((val, key) => {
return (
<tr key={key}>
<td>{key+1}</td>
<td>{val.name}</td>
<td>{val.stars}</td>
<td>{val.percentage}</td>
</tr>
)
})}
</tbody>
</table>
I tried making another state that was an int in case this was being caused due to it being an array but that didnt help.
The table just remains empty even though the rankings variable has data. If I put the data that is in the rankings variable into the constructor the table looks as intended so I don’t think that the data is a problem

