The "use server" directive must be at the top of the file.
Answered
In&Out posted this in #help-forum
In&OutOP
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?
7 Replies
In&OutOP
"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?
In&OutOP
"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