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("")
}
I get the error in the picture below when I try to run that function. I have tried using google cloud firestore's timestamp as an alternative but I don't know what the problem with this is.