I'm building a React App with Firebase and my component is constantly re-rendering.
I tried some things that didn't work (because they couldn't work, like settig useState inside the callback).
This is the code, please help!
const [user, setUser] = useState(null);
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');
const msgRef = ref(db, 'messages');
onValue(msgRef, snapshot => {
const msg = snapshot.val();
if (Object.values(msg) != messages) {
setMessages(Object.values(msg));
}
})
Also, I know it is re-rendering because of this code beacuse I console.logged it.