Next.js Discord

Discord Forum

CSS class not being applied

Unanswered
Persian posted this in #help-forum
Open in Discord
PersianOP
Hi there, I'm trying to create a simple register form and be able to display a message to the user if necessary. my jsx looks like this:
export default function RegistrationForm() {
  const [username, setUsername] = useState("");
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");
  const [error, setError] = useState("");
  const [success, setSuccess] = useState("");

  // [...] form validation and sending data to the backend
  
    return (
    <div className={styles.page}>
      <main className={styles.main}>
        <form className={styles.form} onSubmit={handleRegister}>
          <h1>Create an account</h1>
          <input
            className={styles.input}
            type="text"
            placeholder="Username"
            value={username}
            onChange={e => setUsername(e.target.value)}
            required
          />
          <input
            className={styles.input}
            type="email"
            placeholder="E-mail"
            value={email}
            onChange={e => setEmail(e.target.value)}
            required
          />
          <input
            className={styles.input}
            type="password"
            placeholder="Password"
            value={password}
            onChange={e => setPassword(e.target.value)}
            required
          />
          {success && <div className={styles.success}>{success}</div>}
          {error && <div className={styles.error}>{error}</div>}
          <button className={styles.button} type="submit">Continue</button>
        </form>
      </main>
    </div>
  );
}

however when the success or error variable aren't null the class isn't getting applied:

1 Reply

PersianOP
so the div gets displayed but without the class being applied