Eso*_*ore 6 firebase reactjs redux styled-components
我在遵循本教程时遇到以下错误https://www.youtube.com/watch?v=QiTq5WrWoJw&t=8176s
我在将个人消息连接到 Firebase 应用程序时遇到问题。我在控制台中的错误集中在以下代码上。
我正在尝试在 firebase 内的单个“房间”中发送消息,因此每个房间内都有独特消息的房间集合。
function ChatInput(channelName, channelId) {
const [input, setInput] = useState('');
const sendMessage = (e) => {
e.preventDefault(); //prevents refresh of the page
if(!channelId) {
return false;
}
db.collection("rooms").doc(channelId).collection("messages").add({
message: input,
timestamp: firebase.firestore.FieldValue.serverTimestamp(),
user: 'Daniel Peters',
userImage:'https://wallpapercave.com/wp/j8Sd6Uv.jpg',
});
setInput('');
};
return (
<ChatInputContainer>
<form>
<input value={input} onChange={(e) => setInput(e.target.value)} placeholder= {`Message #${channelName}`} />
<Button hidden type='submit' onClick={sendMessage}>
SEND
</Button>
</form>
</ChatInputContainer>
)
}
export default ChatInput;
Run Code Online (Sandbox Code Playgroud)
我尝试了不同版本的 redux 和 firebase,看看这是否是问题所在,但问题显然没有解决。任何指导都会很棒!
rah*_*ver 19
我刚刚遇到这个问题,最终我的“错误”是我试图使用数字 id 作为 firestore 文档键。
所以这个给出了这个u.indexOf is not a function错误:
let ref = db.collection(`userPreferences/${userId}/venues`).doc(venue.id);
Run Code Online (Sandbox Code Playgroud)
这个在哪里工作:
let ref = db.collection(`userPreferences/${userId}/venues`).doc(`${venue.id}`);
Run Code Online (Sandbox Code Playgroud)
我只是用引号将第二个括起来,使其成为一个字符串。希望这能拯救某人的一天!
| 归档时间: |
|
| 查看次数: |
4580 次 |
| 最近记录: |