1import React, { useState, useEffect } from 'react';
2function Example() {
3 const [count, setCount] = useState(0);
4
5 // Similar to componentDidMount and componentDidUpdate:
6 useEffect(() => {
7 // Update the document title using the browser API
8 document.title = `You clicked ${count} times`;
9 });
10
11 );
12}
1useEffect(() => {
2 messagesRef.on('child added', snapshot => {
3 const message = snapshot.val();
4 message.key = snapshot.key;
5
6 setMessages(messages.concat(message)); // See Note 1
7}, []); // See Note 2