소개
게시글
질문&답변
2023.12.19
타입스크립트 질문
저 강사님분처럼 해봤는데도 에러가 뜨네용... signupModal.tsx import onSubmit from "../_lib/signup"; const [state, formAction] = useFormState (onSubmit, { message: null }); signup.ts 파일 "use server"; import {redirect} from "next/navigation"; export default async (prevState: any, formData: FormData) => { if (!formData.get('id') || !(formData.get('id') as string)?.trim()) { return { message: 'no_id' }; } if (!formData.get('name') || !(formData.get('name') as string)?.trim()) { return { message: 'no_name' }; } if (!formData.get('password') || !(formData.get('password') as string)?.trim()) { return { message: 'no_password' }; } if (!formData.get('image')) { return { message: 'no_image' }; } let shouldRedirect = false; try { const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/users`, { method: 'post', body: formData, credentials: 'include', }) console.log(response.status); if (response.status === 403) { return { message: 'user_exists' }; } console.log(await response.json()) shouldRedirect = true; await signIn("credentials", { username: formData.get('id'), password: formData.get('password'), redirect: false, }) } catch (err) { console.error(err); return; } if (shouldRedirect) { redirect('/home'); // try/catch문 안에서 X } } 이렇게 했는데 useFormState의 onSubmit부분에서 밑의 코드처럼 에러가 발생하네요ㅠㅠㅠㅠ Argument of type '(prevState: any, formData: FormData) => Promise ' is not assignable to parameter of type '(state: { message: string | null; }) => { message: string | null; } | Promise '. Target signature provides too few arguments. Expected 2 or more, but got 1.
- 0
- 3
- 711
질문&답변
2023.01.15
Vue3 Composition API - computed
다시 들으니 fullName.value에 값을 대입하면 set함수의 매개변수로 들어간다고 하셨는데 무조건 .value 로 접근을 해야 하는것인가요?
- 0
- 1
- 257