4 글 보임 - 1 에서 4 까지 (총 4 중에서)
-
글쓴이글
-
2024년 6월 5일 01:53 #124963
송지오참가자'use client' 사용하면 await , async 사용 못 한다는데 let session = await getServerSession(authOptions); 이 문장 기능이 필요한데 어떻게 대체하나요?? 아래 코드에서 axios로 로그인중인 사용자 이름까지 서버로 보내고싶은데 let session = await getServerSession(authOptions) 정의 하고 session.user.username 보내려고하면 Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server. 라고 뜨네요
'use client'
import axios from "axios"; import { useState } from "react";
export default function ListClient() {
const [todo, setTodo] = useState(""); const [deadline, setDeadline] = useState("");
const todoSubmitHandler = () => { axios.post("http://localhost:8080/api/post-data", { todo, deadline}) .then(res => { console.log(res); }) .catch(err => { console.error(err); }); };
return ( <div className="list-container"> <div className="input-container"> <label>할일 </label> <input type="text" onChange={(e) => setTodo(e.target.value)} autoComplete="off" /> <p> </p> <label>기한 </label> <input type="text" placeholder="월/일" onChange={(e) => setDeadline(e.target.value)} maxLength={5} autoComplete="off" /> <p> </p> <button onClick={todoSubmitHandler}>추가</button> </div> </div> ); }
자세한 코드 확인 필요하시면 https://github.com/KingZio/codingapple-next 이거 봐주세여 위에 코드는 app/list/page.js입니다
2024년 6월 5일 08:57 #124968
codingapple키 마스터client component에선 useSession 사용해서 출력합시다 아니면 서버컴포넌트에서 props로 보내도 됩니다
-
글쓴이글
4 글 보임 - 1 에서 4 까지 (총 4 중에서)
- 답변은 로그인 후 가능합니다.