#should i just send it as a``` return res
1 messages · Page 1 of 1 (latest)
no just do it normally like res.json({ id: transactionId })
and use 2xx status codes for this
your api route is not actually redirecting anything so don't use 3xx
no you don't need to worry about status codes here
just res.json?
router.push is a client-side redirection
so no need to worry about status codes
just use 2xx codes, like 200, or nothing at all (implicit 200)
return res.json({ id: transactionID })
so that defaults to 200 code right
alr imma first log the res to see if the id came through
damn i dont see the id anywhere
do i log response.body
const res = await fetch();
const json = await res.json();
console.log(json);
const response = await fetch(endpoint, options);
const formError = await response.json().then(res => res.error).catch(err => console.error(err));
console.log(response.json())
const code = response.status;```
only when i log the .json
you can only call .json once
shoot ok
so i need to get the id and the error i send
the error should be in the json as well
so just do this
const res = await fetch();
const json = await res.json();
console.log(json);
and handle error toast logic with the json object
alr it worked
lemme try the redirect
where should i declare this?
const router = useRouter()```
cause rn im using the hook wrong
function MyClientComponent() {
const router = useRouter();
...
}
export default function Form() {
const formSubmit = async (event) => {
const router = useRouter();
event.preventDefault();
//...```
ok so now it "redirected"
no incorrect. Move const router = useRouter() outside
💀
mb
wait is it cuase of app dir
alr it worked, but it showed the toast and then redirected
well that depends on how you set up your toast
you can also try calling showToast after router.push
i did
same thing still
using this
sorry to bother, but any idea how to show the toasrt after redirect?>
wdym
like the containers?
What containers? Just follow their guide and set the toasts up
ye but then everything needs to be clinet side right
if i do
<ToastContainer/>
inside of my root
Yes
so every comp is then client side
so do i put this on my highets page.jsx
No, in your root layout
ok
ok so now in the root everything works with toast container
but when i submit form, it redirects but no toast shows up
call showtoast in the event handler
before redirecting
i dont have show toast tho
call whatever you need to show the toast