Skip to content

Instantly share code, notes, and snippets.

@oney
Created June 3, 2022 09:05
Show Gist options
  • Save oney/b51a40eb83756c0c235fcce68bc119cf to your computer and use it in GitHub Desktop.
Save oney/b51a40eb83756c0c235fcce68bc119cf to your computer and use it in GitHub Desktop.
import { useEffect } from "react-better-effect";
function Chat({ selectedRoom }) {
const theme = useContext(ThemeContext);
useEffect(($) => {
const socket = createSocket('/chat/' + selectedRoom);
socket.on('connected', async () => {
await checkConnection(selectedRoom);
showToast($.theme, 'Connected to ' + selectedRoom);
// 😋 get the latest 'theme' value from $
});
}, [selectedRoom], {theme}); // 🤓 inject 'theme' here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment