Beginner React movie list project - Needs suggestions and improvement
Hello everyone!
I'm a beginner in React and I'm learning concepts like components, props, state, and event handling.
I have built a small movie list project where I display a list of movies using a component. I have also added Like and Dislike functionality using useState.
I would love it if you could please review my code and give me feedback:
What am I doing correctly?
Where am I making mistakes?
Which parts can I improve?
Any better approaches I could use?
Thank you so much for your time and help!
Here is the code:
MovieCard component
https://pastecord.com/rohumedezo.js
App.jsx
https://pastecord.com/ykujutuhaf.js
4 Replies
in your app.jsx
No need for another state as dislike
Do like this
function IncreaseLike(){
setLikes(prev=>prev+1)
}
function DecreaseLike(){
if(likes > 0){
setLikes(prev=> prev -1)
}
}
Okay
@vic thanks!
I have a qs as I'm learning react and I'm a beginner is it important to use the best approaches to write the code or just write the code that features works
I'm not that much experienced guy I'm also like learn react 2 months ago , I think yes just do code that feautures work
Also for the movie card component :
Here u send props like this :
<MovieCard
key={index}
src={Movie.src}
name={Movie.name}
genre={Movie.name}
rating={Movie.rating}
/>
U r method would work but what u can try was just send that array to that component
<MovieCard arr={movies} />
And in MovieCard.jsx
Function Moviecard({arr})
{
if(Array.isArray(arr) && arr.length > 0 ) {
return <div>
{arr.map((item,ind)=>{
return <p> {item.movie} </p>
})
}
</div>
}
}
@vic okay thanks! i will try this method