Home > front end >  My ReactJS pastReviews page component is no rendering when it is live
My ReactJS pastReviews page component is no rendering when it is live

Time:04-07

When I try to load the past reviews page of my React application, I am greeted with a blank page and the following error in my react dev tools console

Uncaught Error: PastReviews(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null"

The following consists of the function for the PastReviews page component:

function PastReviews(){
let navigate = useNavigate();
const [user] = useAuthState(auth);
if(!user){
    navigate("/");
}
const [review, setReview] = useState([]);
const reviewCollectionRef = collection(db, "review");
//this useEffect hooks contains an asynchronous function what fetches the dtata from firestore
useEffect(() => {

    const getReview = async () =>{
        const data = await getDocs(reviewCollectionRef);
        setReview(data.docs.map((doc) => ({...doc.data(), id: doc.id})))
    };
    getReview();
}, 
[]);
  
 //the following code displays the past reviews details from the firebase dataabase
 {review.map((review) => {
    return(
        <><Header /><Card>
            {""}
            <label className='reviewQ'>General description of your experience with the module</label>
            

            <label className='reviewQ'>What do you think of the lecturers teaching</label>
            

            <label className='reviewQ'>How were the module contents taught?</label>
            

            <label className='reviewQ'>How did you feel about the assessments</label>
            

            <label className='reviewQ'>How could teaching be improved</label>
          

            <label className='reviewQ'>How could assessments be  improved</label>
            

            <label className='reviewQ'>what did you think of the workload of this module</label>
       

            <label className='reviewQ'>give some extra feedback</label>

            <p>{review.q1}</p>
            <p>{review.q2}</p>
            <p>{review.q3}</p>
            <p>{review.q4}</p>
            <p>{review.q5}</p>
            <p>{review.q6}</p>
            <p>{review.q7}</p>
            <p>{review.q8}</p>
        </Card><Footer /></>
    ); 
})}
 

}

Any help and advice will be appreciated.

CodePudding user response:

You are missing a return statement in the component. Also check for review to be defined.

return review && review.map((review) => {...})
  • Related