I am trying to import a script in react from a file but it is returning in a way that I do not want it to return. It is messing up the project. Here is the code for both files:
Certification.js:
const fetchCertification = async (type, id) => {
if (type === "movie") {
const { data } = await axios.get(
`https://api.themoviedb.org/3/movie/${id}/release_dates?api_key=${
import.meta.env.VITE_API_KEY
}`
);
const filteredData = {
id: data.id,
results: data.results.map((x) => ({
...x,
release_dates: x.release_dates.filter(
(date) => date.certification !== ""
),
})),
};
if (
filteredData?.results?.find(({ iso_3166_1 }) => iso_3166_1 == "GB")
?.release_dates[0]?.certification ||
filteredData?.results?.find(({ iso_3166_1 }) => iso_3166_1 == "US")
?.release_dates[0]?.certification !== undefined
) {
return (
filteredData?.results?.find(({ iso_3166_1 }) => iso_3166_1 == "GB")
?.release_dates[0]?.certification ||
filteredData?.results?.find(({ iso_3166_1 }) => iso_3166_1 == "US")
?.release_dates[0]?.certification
);
} else {
return false;
}
} else {
const { data } = await axios.get(
`https://api.themoviedb.org/3/tv/${id}/content_ratings?api_key=${
import.meta.env.VITE_API_KEY
}`
);
const filteredData = data?.results?.filter((x) => x.rating !== 0);
if (
filteredData?.find(({ iso_3166_1 }) => iso_3166_1 == "GB")?.rating ||
filteredData?.find(({ iso_3166_1 }) => iso_3166_1 == "US")?.rating !==
undefined
) {
return (
filteredData?.find(({ iso_3166_1 }) => iso_3166_1 == "GB")?.rating ||
filteredData?.find(({ iso_3166_1 }) => iso_3166_1 == "US")?.rating
);
} else {
return false;
}
}
};
Home.jsx:
import {fetchCertification} from Certification.js;
const certificationData = fetchCertification(movie, 13453);
console.log(certificationData);
The console is not returning the movies well for some reason. I should get a string with the certification. Please see if there is anything wrong. Thank you.