How to conditionally render this modal in server component?
Answered
Rex posted this in #help-forum
RexOP
I want to convert the following component to the server component
"use client";
import { useCallback, useState } from "react";
import Modal from "@/components/ui/Modal/Modal";
import profileJson from "./profile.json";
import ProfileForm from "../components/ProfileForm";
const ProfileInfo = () => {
const [modal, setModal] = useState(false);
// check if already have a profile
return (
<section className="p-[10px] md:p-[20px] lg:p-[38px] bg-white rounded-[10px] z-20">
<h3 className="h3 text-[#13013C]">Personal information.</h3>
<ProfileForm />
{/* Modal */}
<div className={` ${modal ? "block " : "hidden"} `}>
<Modal
className=""
heading="For parents signing up for a child"
closeModal={() => setModal(!modal)}
>
<ul className="text-grey f14 list-disc ">
<li className="mt-[25px]">{profileJson[0].point1}</li>
<li className="mt-[25px]">{profileJson[0].point2}</li>
<li className="mt-[25px]">
{profileJson[0].point3}{" "}
<span className="text-purple fw500 cursor-pointer">
Support Team.
</span>
</li>
</ul>
</Modal>
</div>
</section>
);
};
export default ProfileInfo;Answered by Giant panda
You can have a GET and a POST operation in parallel on the same endpoint
8 Replies
RexOP
modal is displayed based on the state and we can't do that in server components
Giant panda
You answered your own question. Since the component in itself relies on interactivity it cannot be a server component.
RexOP
follow up question
Here is what I want to acheive
"get
I am using prisma to interact with db and I can't use prisma client in client components so how should I make request to the db?
Should I make api route under api's folder? But the issue is I already have
"get
user record form the db"I am using prisma to interact with db and I can't use prisma client in client components so how should I make request to the db?
Should I make api route under api's folder? But the issue is I already have
user route under api/user/route.js through which I create usersGiant panda
You can have a GET and a POST operation in parallel on the same endpoint
Answer
Giant panda
There is nothing wrong with it
RexOP
It might sound absurd but I haven't seen a single example of this. Should have been obvious since I have played around with express
Thank you so much