Next.js Discord

Discord Forum

next js App router

Unanswered
Western thatching ant posted this in #help-forum
Open in Discord
Western thatching antOP
Hi guys, I'm trying the new App router and I'm really struggling,
all I did Is i created a file inside the app directory like this news/page.jsx, and I this is my code:
"use client";
import { useState } from "react";
const NewsLetter = () => {
const [email, setEmail] = useState("");

const createNewsLetter = async (e) => {
e.preventDefault();
console.log("email", gaga);
};

return (
<form onSubmit={createNewsLetter}>
<div>
<label htmlFor="email">NewsLetterEmail</label>{" "}
<input
type="email"
id="email"
name="email"
value={email}
placeholder="Email"
onChange={(e) => setEmail(e.target.value)}
required
/>
<button type="submit">Submit</button>
</div>
</form>
);
};

export default NewsLetter;
whenever i go to http://localhost:3000/news, my page shows up as expected but when I fill the input field and hit the submit button all that happens is my url changes to http://localhost:3000/news?email@email.com but nothing else happens no console log working, no state change working? am I doing something wrong?

0 Replies