Skip to content

Instantly share code, notes, and snippets.

@LuffyAnshul
Created January 17, 2021 07:01
Show Gist options
  • Save LuffyAnshul/11f23bc1628c527c5c8578d1ea46a239 to your computer and use it in GitHub Desktop.
Save LuffyAnshul/11f23bc1628c527c5c8578d1ea46a239 to your computer and use it in GitHub Desktop.
Private Chat React Native - Functions to handle async events
async function handlePress() {
const _id = Math.random().toString(36).substring(7);
const user = { _id, name };
await AsyncStorage.setItem('user', JSON.stringify(user));
setUser(user);
}
async function handleSend(messages) {
const writes = messages.map((m) => chatsRef.add(m));
await Promise.all(writes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment