Error useSearchParams
Answered
Netherland Dwarf posted this in #help-forum
Netherland DwarfOP
Hey, I have a error with searchparams, this error come when i try build the app.
I look in the doc and i cant solve this error.
Error :
Code :
I look in the doc and i cant solve this error.
Error :
⨯ useSearchParams() should be wrapped in a suspense boundary at page "/login". Read more: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout
Error occurred prerendering page "/login". Read more: https://nextjs.org/docs/messages/prerender-errorCode :
"use client";
import "../../../style/login.css";
import Link from "next/link";
import React, { useRef, Suspense } from "react";
import { signIn } from "next-auth/react";
import { useSearchParams } from "next/navigation";
const LoginPage = () => {
const email = useRef("");
const password = useRef("");
const searchParams = useSearchParams();
const callbackUrl = searchParams.get("callbackUrl");
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
await signIn("credentials", {
email: email.current,
password: password.current,
redirect: true,
callbackUrl: callbackUrl ?? "http://localhost:3000",
});
};
return (
<Suspense fallback={<div>Chargement...</div>}>
<div className="container">
<form onSubmit={onSubmit}>
<div>
<h1>Connexion</h1>
<p>Connectez-vous</p>
</div>
<div className="form-group">
<input
type="email"
placeholder="your@mail.com"
onChange={(e) => (email.current = e.target.value)}
/>
<input
type="password"
placeholder="********"
onChange={(e) => (password.current = e.target.value)}
/>
</div>
<button type="submit">Connectez-vous</button>
<Link href="/">Annuler</Link>
</form>
</div>
</Suspense>
);
};
export default LoginPage;Answered by American Crow
The Suspense must be one level higher. (Wrapping the <Login> Component, not within it)
Or use a
Or use a
loading.tsx in the same folder next to the page.tsx e.g. app/login/loading.tsx2 Replies
American Crow
The Suspense must be one level higher. (Wrapping the <Login> Component, not within it)
Or use a
Or use a
loading.tsx in the same folder next to the page.tsx e.g. app/login/loading.tsxAnswer
Netherland DwarfOP
ok it's good, ty for you help