0

i'm able to limit the number of results i receive from mongoDB using this

  try {
    
    await connectMongo();

    const students = await Student.find().limit(5)
    console.log('FETCHED Students');

    res.status(200).json(students)

    return

} catch (error) {
    console.log(error);
    res.json({ error })
}

but i'm not sure how to effect the pagination on the client side of things i've tried finding a way but none has worked so far for me

 const showinfo = async () => {
    const StudentResponse = await fetch("/api/admin/student/fetchStudent", { method: "Get" })
        .then(res => res.json()) as Students[]

    SetStudents(StudentResponse)

}

that's how i'm requesting the api

 {students.map((student: {
                    _id: string
                    firstname: string
                    matricno: string
                    lastname: string
                }) =>
                    <div
                        key={student._id}
                    >



                        <Link
                            href={`/ADMIN2823/Students/${student._id}`}
                        >

                            <div className="bg-primary rounded-lg  p-3 hover:bg-primary/80">


                                <div className="flex items-end space-x-3">

                                    <div className="w-1/2  relative">


                                        <div className="text-black   font-bold text-lg">
                                            {student.firstname} {student.lastname}
                                        </div>

                                        <p
                                            className="text-gray-400"
                                        >
                                            {student.matricno}
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </Link>






                    </div>
                )}

That’s how i'm handling the response

  • Does this answer your question? [How to implement pagination in React](https://stackoverflow.com/questions/40232847/how-to-implement-pagination-in-react) – Yilmaz Jun 21 '23 at 22:55

0 Answers0