NextJS 14 custom Data fetch from client to server

131 Views Asked by At

I use NextJS 14.0.3 with App router, Firebase for auth and Airtable for DB.

I want to fetch data from Airtable using Airtable library (not await fetch function) based upon the user details which was obtained from Airtable (client side fetching) during Login and stored as context.

I have another page component (server) and I want to fetch some data directly using server with few values from the context which I obtained earlier.

//function to get data     
export const getJobs = async (options) => {
return new Promise((resolve, reject) => {
        base('example').select(options).firstPage((err, records) => {
            if (err) {
                // console.error("Error:", err);
                reject("Error");
                return;
            }
            // console.log('Retrieved', records);
            resolve(records?.map(record => record._rawJson.fields));
        });
    });
}

//page.js
 const JobsList = async () => {

 var jobData = await getJobs(optionFromContext);

 return <h1>{jobData.length}</h1>
}

I tried using zustand and server-only-context, but I'm confused using the both.

I need some guidance regarding this whether to store the user details in cache or how to proceed further

0

There are 0 best solutions below