Skip to content
Advertisement

Show rating stars in react not showing any stars

I am building website of Mangas where each Manga has star reviews. I am done with backend but since I am very new to react, I can not figure out how to display stars on webpage. I’m developing it in Django so: id=”{{ rating }}” is a loop where I display each manga with title, rating and so on. console.log(prop.id) returns each manga rating 2 times so mangas with ratings 2, 4, 5 are logged as 2, 4, 5, 2, 4, 5.

code

JavaScript

error: Nothing was returned from render

Advertisement

Answer

I’m making two assumptions. 1) that your data is an array of objects, and 2) that your rating will be “out of five stars”

Have two functions: one to map over the array of objects, and another to create the stars for each object.

JavaScript
JavaScript
JavaScript

To (mostly) satisfy Cesare’s comment here’s the same code but as separate components.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement