javascript - FirebaseError:使用无效数据调用的函数 addDoc()。不支持的字段值:未定义
问题描述
function Chat() {
const [input, setInput] = useState("")
const [seed, setSeed] = useState("")
const {personid} = useParams()
const [personname, setPersonname] = useState("")
const [messages, setMessages] = useState([])
const [{user}, dispatch] = useStateValue()
useEffect(() => {
if (personid) {
db.collection("people")
.doc(personid)
.onSnapshot((snapshot) =>
setPersonname(snapshot.data().name));
db.collection("people")
.doc(personid)
.collection("messages")
.orderBy("timestamp", "asc")
.onSnapshot((snapshot) =>
setMessages(snapshot.docs.map(doc =>doc.data()))
)
}
}, [personid])
useEffect(() => {
setSeed(Math.floor(Math.random()*1000))
}, [personid])
const sendmessage = (e) => {
e.preventDefault()
console.log("The input is ", input);
db.collection("people").doc(personid).collection("messages").add({
message: input,
name: user.displayName,
timestamp: firebase.firestore.FieldValue.serverTimestamp(),
})
setInput("")
}
当我尝试运行该功能时,出现下图中的错误。我曾尝试使用 google cloud firestore 的时间戳作为替代方案,但我不知道这是什么问题。
解决方案
推荐阅读
- javascript - C:\Program Files\Docker Toolbox\docker.exe:引用格式无效:存储库名称必须为小写
- django - drf-yasg 自定义 SwaggerUIRenderer
- bash - 将目录文件复制到另一个目录的问题
- dht - 为什么使用无跟踪器下载时 DHT 找不到资源?
- javascript - 当我使用具有匿名功能的外部 ja 文件时,我收到 Uncaught TypeError: Cannot read property 'addEventListener' of null
- c# - 派生对象映射的奇怪 Automapper 行为
- r - 基于共享组值的新因子列 [R]
- xamarin - 如何在堆栈布局/列表视图 [Xamarin.Forms] 的每一行中显示视频?
- python - 使用 For 循环生成数据框
- enumeration - Presto 中是否有 ENUM 类型?