Next.js Discord

Discord Forum

Data Fetching

Unanswered
~/.BeastieNate5 posted this in #help-forum
Open in Discord
I have a simple data fetching program that I want to get data from a API. I called the program ScriptReader.js. I have a client component that I want to use the function in the ScriptReader program to get the data. The thing is I noctied that the ScriptReader function is running on the client. Is there anyway I can get it to execute on the server instead

ScriptReader.js
function getScript() {
    // Fetch data
}

export default getScript;


Client Component
function handleClick() {
  const script = getScript();
}

3 Replies

@~/.BeastieNate5
Add the "use server" to the top of script reader.js
and also make it export an async function