Next.js Discord

Discord Forum

The "use server" directive must be at the top of the file.

Answered
In&Out posted this in #help-forum
Open in Discord
Why do I get this error even tho I did put "use server" at top of file?
Answered by Common Nighthawk
Correct me if I'm wrong. But isn't components by default server rendered if one is not using "use client"? The "use server" directive is mainly used for server side actions?
View full answer

7 Replies

"use server";
import styles from "./Namemodal.module.css";
import { CSSProperties } from "react";
import { Archivo } from "next/font/google";
const archivo = Archivo({
  subsets: ["latin"],
  weight: ["400", "500", "600"],
});
Common Nighthawk
Is this the full content of the file? And, where do you import and how do you use this file?
@Common Nighthawk Is this the full content of the file? And, where do you import and how do you use this file?
"use server";
import styles from "./Namemodal.module.css";
import { CSSProperties } from "react";
import { Archivo } from "next/font/google";
const archivo = Archivo({
  subsets: ["latin"],
  weight: ["400", "500", "600"],
});
let opened: boolean = true;
function Namemodal() {
  const containerStyle = {
    pointerEvents: opened
      ? ("auto" as CSSProperties["pointerEvents"])
      : ("none" as CSSProperties["pointerEvents"]),
  };
  return (
    <div className={styles.Container} style={containerStyle}>
      <div className={styles.Modal}>
        <div className={styles.Title}>
          <div className={archivo.className}>Enter your username</div>
        </div>
        <div></div>
      </div>
    </div>
  );
}

export default Namemodal;
And I use it in layout file
Like any other component
Common Nighthawk
Correct me if I'm wrong. But isn't components by default server rendered if one is not using "use client"? The "use server" directive is mainly used for server side actions?
Answer