import { useEffect, useState } from 'react'; code example
Example 1: useeffect react
useEffect(() => {
// code goes here
return () => {
// cleanup code codes here
};
},[]);
Example 2: useeffect componentdidmount
useEffect(() => {
messagesRef.on('child added', snapshot => {
const message = snapshot.val();
message.key = snapshot.key;
setMessages(messages.concat(message)); // See Note 1
}, []); // See Note 2