'use client' async function Teachers (){ const response = await fetch('http://localhost:8000/teachers', }) const data = await response.json(); const [showNames , setShowNames] = useState(false); // Unable to use button due to error const teacherHandler = ()=>{ setShowNames (!showNames) } return ( <div className="mt-10"> <div className=" text-center font-DanaDemiBold text-3xl text-white"> <h1 className="w-full bg-slate-900 mb-5">Teachres</h1> <button onClick={teacherHandler} className="p-3 bg-green-600 rounded-lg mt-5 hide-button">Show/Hide Teachers Name</button> ); </div> <div className=" flex justify-center items-center flex-wrap p-2 gap-3 my-10 "> { !showTeachers?null : data.map(item=>( <div key={item.id} className=" w-1/3 h-[300px] flex justify-between items-center shadow-lg bg-slate-300 rounded-lg teacher-card"> <div className="flex flex-col m-10 gap-y-5"> <div className="flex gap-x-2"> <h3> Name: </h3> <span>{item.firstname}</span> <span>{item.lastname}</span> </div> <div className="flex gap-x-2"> <h3> Email: </h3> <span>{item.email}</span> </div> <div className="flex gap-x-2"> <h3> Date of Birth: </h3> <span>{item.birthDate}</span> </div> <div className="flex gap-x-2"> <h3> phone: </h3> <span>{item.mobile}</span> </div> <div className="flex gap-x-2"> <h3> Address: </h3> <span>{item.address}</span> </div> </div> <div className="w-36 h-36 m-10"> <img className="rounded-full" src={item.profileImg} alt="profile"/> </div> </div> ))} </div> </div> ) } export default Teachers;
Thank you for your assistance. I am facing difficulties using the button and its corresponding function due to an error message indicating that async/await is not yet supported in Client Components, only Server Components.