How can I pass the select values from a component to a page.tsx file?
Answered
Ocicat posted this in #help-forum
OcicatOP
I wanna pass the values from the component to the page.tsx so I can use them dynamically. I know I could do this with an useState in page.tsx but I don't wanna transform it in a client component.
page.tsx:
const TopTracksTable: React.FC<TopTracksTableProps> = ({ tracks, title }) => {
return (
<div className="rounded-lg bg-secondary border border-border">
<SectionTitle title={title} />
<Select>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select a time range" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Time Range</SelectLabel>
<SelectItem value="short_term">Short Term</SelectItem>
<SelectItem value="medium_term">Medium Term</SelectItem>
<SelectItem value="long_term">Long Term</SelectItem>
</SelectGroup>
</SelectContent>
</Select>page.tsx:
export default async function Page() {
const session = await auth();
if (!session?.user) return null;
const accessToken = session.access_token ?? "";
const [radarChartData, topGenres, topTracks] = await Promise.all([
getRadarChartData(accessToken),
fetchTopGenres(accessToken),
fetchTopTracks(accessToken, "medium_term", 5),
]);14 Replies
so you want to pass data from a client component to a its page? @Ocicat
@Arinji so you want to pass data from a client component to a its page? <@327741242505166848>
OcicatOP
hmm in this case yes. I'm just trying to find a way to keep the page as a server component. I wanna let the user to select a value, then use that value in the fetch function that I'm callin inside the page.tsx
like dump it in the url
and have your page listen to the url
@Arinji put it in the search params
OcicatOP
will this cause a page refresh?
Answer
use that
Thats how i append to the url nicely, with a nice submit setup as well
https://github.com/Arinji2/imagee/blob/master/src/app/dashboard/manage.tsx#L42-L49
https://github.com/Arinji2/imagee/blob/master/src/app/dashboard/manage.tsx#L42-L49
OcicatOP
I’ll try this approach
OcicatOP
@Arinji thank you, it worked!
No worries, mark a solution @Ocicat
Original message was deleted
Boop