Value sent from frontend to backend

Trine - Aug 29 - - Dev Community

I have defined the selectedCategory in page.tsx. I want then to send to retrieve/import selectedCategory in the file route.ts, but it always ends up being empty.

Since page.tsx is what is rendered for the user, I have also tried to fetch selectedCategory using useEffect and useState, but it does not seem to work.

Anyone can help?

page.tsx

"use client";

import React from "react";
import styles from "./page.module.css"; // use simple styles for demonstration purposes
import Chat from "../../components/chat";
const selectedCategory = "category1";
console.log("Selected category is: ", selectedCategory);

const Home = () => {

  return (
    <main className={styles.main}>
      <div className={styles.container}>
        <Chat />
      </div>
    </main>
  );
};

export default Home;
export { selectedCategory };
Enter fullscreen mode Exit fullscreen mode

route.ts (only relevant code rendered)

import { openai } from "@/app/openai";
import { selectedCategory } from "@/app/examples/first-chat/page";
console.log(selectedCategory)
Enter fullscreen mode Exit fullscreen mode
.
Terabox Video Player