Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error : reviews not iterable #6

Open
chandravaibhav98 opened this issue Aug 4, 2024 · 0 comments
Open

Error : reviews not iterable #6

chandravaibhav98 opened this issue Aug 4, 2024 · 0 comments

Comments

@chandravaibhav98
Copy link

chandravaibhav98 commented Aug 4, 2024

I observed Error: reviews not iterable on trying to create a Review, being traced to the addReview on Reviews Component.
I've tested the same on your project and the issue is observed there as well.

const addReview = async (e) => {
		e.preventDefault();
		const rev = revText.current;
		try {
			const response = await api.post("/api/v1/reviews", { reviewBody: rev.value, imdbId: movieId });
			const updatedReviews = [...reviews, { body: rev.value }];
			rev.value = "";
			setReviews(updatedReviews);
		} catch (err) {
			console.error(err);
		}
	};

The fix being on App : getMovieData()

// Changing
setReviews(singleMovie.reviews);
// To this
setReviews(singleMovie.reviewIds);

The 'singleMovie' response has a property of 'reviewIds' and not 'reviews'.

const getMovieData = async (movieId) => {
try {
	const response = await api.get(`/api/v1/movies/${movieId}`);
	const singleMovie = response.data;

	setMovie(singleMovie);
	setReviews(singleMovie.reviewIds);
} catch (err) {
	console.error(err);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant