how do i check if the input is clear?

All you need to do is prevent your submit function from calling firebase if your input is empty.

const sendMessage = (e) => { 
 e.preventDefault();
 if (input.length <= 0) return; // This will end the function here if your input is empty

 db.collection('channels').doc(channelId).collection('messages').add({
     timestamp: firebase.firestore.FieldValue.serverTimestamp(),
     message: input,
     user: user,       
 });
 setInput('')
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top