Expected type 'dh', but it was: a custom xn object
FirebaseError: Expected type 'dh', but it was: a custom xn object
Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
import { query, addDoc } from "firebase/firestore/lite";
import { query, addDoc } from "firebase/firestore";
timestamp 의 형식의 경우
serverTimestamp()을 사용
import {
addDoc,
collection,
serverTimestamp,
Timestamp,
} from "firebase/firestore";
const Chat = () => {
const user = useAppSelector((state) => state.user.user);
const channelId = useAppSelector((state) => state.channel.channelId);
const [inputText, setInputText] = useState<string>("");
const docRef = await addDoc(
collection(
db,
"channels",
String(channelId),
"messages"
),
{
timestamp: serverTimestamp(),
message: inputText,
user: user,
}
);
...
};
<span className="messageTimestamp">
{timestamp?.toDate().toLocaleString()} // 2023. 6. 5. 오전 3:06:04
</span>