Skip to content

Instantly share code, notes, and snippets.

@davidchang
Last active September 17, 2024 16:50
Show Gist options
  • Select an option

  • Save davidchang/70bc0a4d185522a9f62edcb158ee1a8f to your computer and use it in GitHub Desktop.

Select an option

Save davidchang/70bc0a4d185522a9f62edcb158ee1a8f to your computer and use it in GitHub Desktop.
import * as Updates from "expo-updates";
import { ThemedText } from "./ThemedText";
import { StyleSheet } from "react-native";
export default function RestartAppButton() {
async function restart() {
try {
const update = await Updates.checkForUpdateAsync();
if (update.isAvailable) {
await Updates.fetchUpdateAsync();
await Updates.reloadAsync();
} else {
Updates.reloadAsync();
}
} catch (e) {
console.error("Failed to restart app:", e);
Updates.reloadAsync();
}
}
return (
<ThemedText style={styles.link} onPress={restart}>
Restart the app
</ThemedText>
);
}
const styles = StyleSheet.create({
link: {
color: "blue",
paddingHorizontal: 24,
textAlign: "center",
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment