-
다이어리 데이터 추가 하기멈멈-토이프로젝트(next.js)2 2024. 8. 29. 16:14728x90
클라이언트 컴포넌트에서 supabase의 메서드 사용 하여 데이터 추가
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { e.preventDefault(); const walkTxt = value.filter((item) => item === "a")[0] ?? ""; const daydate = dateFunc(); const { data, error } = await supabase .from("zwritedb") .insert([ { id: numId, uuid: dataUid, eat: eatTxt, }, ]) .select("*"); console.log(data); if (error) { throw error; } }; <form onSubmit={handleSubmit}> {/* <Suspense fallback={<p>로딩중...</p>}> */} <Dwritebottomicon /> {/* </Suspense> */} <textarea name="content" className="resize-none border border-[#F5BB8C] w-full h-40 p-2.5 bg-transparent outline-none rounded-md" value={textValue} onChange={(e) => setTextValue(e.target.value)} required ></textarea> <button type="submit">등록</button> <button type="button">취소</button> </form>
컴포넌트<Dwritebottomicon/>
<ul style={{ display: "flex" }}> {datas.map((item: ImgType) => ( <li key={item.id}> <button onClick={()=>hadleClick(item.name)} type="button"> <Image src={item.imgurl} width={100} height={100} alt={item.name} /> {item.name} </button> </li> ))} </ul>
작업 하면서 만난 에러
<Dwritebottomicon />에 있는 버튼 형태의 아이콘을 클릭 했는데 그대로 수파베이스와 상호 작용을 해서
버튼 타입을 버튼으로 설정 하여 해결
'멈멈-토이프로젝트(next.js)2' 카테고리의 다른 글
다이어리 데이터 업데이트 (0) 2024.09.04 다이어리 데이터 조회 (0) 2024.08.30 폴더 구조 코드 리팩토링 (2) 2024.08.28 클라이언트 컴포넌트에서 서버 컴포넌트 넣기 (0) 2024.08.12 로그인 uid 리코일 과 세션 (0) 2024.08.07