Hello everyone,
In the code below I built a star component based on the mapped object, but the star rating shows the same value when I click on any of them. how can I make each star rating have its own value based on the selection? pls hellllppppp
You need a single source of truth for the state which in this case would be the mapped data. The state you map is the state you update.
You should create a rating component and map that. Lift the state up and pass the component the props it needs along with the state updater function. Presumably, the ratings are going to be part of something, like a product card or whatnot, so it doesn’t make sense to map the MUI rating component on its own anyway.
The updater function can map over the state, find the object it needs to update the rating for and return a new object with the updated rating value. The assumption here is an array of objects, like an array of product objects with a rating property.