Created
October 12, 2021 20:41
-
-
Save juunegreiros/01e4194a5691d39614c514c0008e01cb to your computer and use it in GitHub Desktop.
Monitoria 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// depende da ordem em que é chamado | |
// começa com use e pode usar outros hooks | |
import { useState, useEffect } from 'react'; | |
function useFriendStatus(friendID) { | |
const [isOnline, setIsOnline] = useState(null); | |
useEffect(() => { | |
function handleStatusChange(status) { | |
setIsOnline(status.isOnline); | |
} | |
ChatAPI.subscribeToFriendStatus(friendID, handleStatusChange); | |
return () => { | |
ChatAPI.unsubscribeFromFriendStatus(friendID, handleStatusChange); | |
}; | |
}); | |
return isOnline; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
function Exemplo() { | |
const [count, setCount] = useState(0); | |
// Similar ao componentDidMount e componentDidUpdate: | |
useEffect(() => { | |
// Atualiza o titulo do documento usando a API do browser | |
document.title = `Você clicou ${count} vezes`; | |
}); | |
return ( | |
<div> | |
<p>Você clicou {count} vezes</p> | |
<button onClick={() => setCount(count + 1)}> | |
Clique aqui | |
</button> | |
</div> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [count, setCount] = useState(0); | |
return ( | |
<div> | |
<p>You clicked {count} times</p> | |
<button onClick={() => setCount(count + 1)}> | |
Click me | |
</button> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment