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AC,CAAC;IAEP,wDAAwD;IACxD,OAAO;QACL,gBAAgB;QAChB,GAAG,YAAY;KAChB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { getNativeStateMachineContextAsync } from './Updates';\nimport { addUpdatesStateChangeListener } from './UpdatesEmitter';\nimport type { UseUpdatesReturnType } from './UseUpdates.types';\nimport {\n currentlyRunning,\n defaultUseUpdatesState,\n reduceUpdatesStateFromContext,\n} from './UseUpdatesUtils';\nimport type { UseUpdatesStateType } from './UseUpdatesUtils';\n\n/**\n * Hook that obtains information on available updates and on the currently running update.\n *\n * @return the structures with information on currently running and available updates.\n *\n * @example\n * ```tsx UpdatesDemo.tsx\n * import { StatusBar } from 'expo-status-bar';\n * import * as Updates from 'expo-updates';\n * import React from 'react';\n * import { Pressable, Text, View } from 'react-native';\n *\n * export default function UpdatesDemo() {\n * const {\n * currentlyRunning,\n * availableUpdate,\n * isUpdateAvailable,\n * isUpdatePending\n * } = Updates.useUpdates();\n *\n * React.useEffect(() => {\n * if (isUpdatePending) {\n * // Update has successfully downloaded\n * runUpdate();\n * }\n * }, [isUpdatePending]);\n *\n * // If true, we show the button to download and run the update\n * const showDownloadButton = isUpdateAvailable;\n *\n * // Show whether or not we are running embedded code or an update\n * const runTypeMessage = currentlyRunning.isEmbeddedLaunch\n * ? 'This app is running from built-in code'\n * : 'This app is running an update';\n *\n * return (\n * <View style={styles.container}>\n * <Text style={styles.headerText}>Updates Demo</Text>\n * <Text>{runTypeMessage}</Text>\n * <Button pressHandler={() => Updates.checkForUpdateAsync()} text=\"Check manually for updates\" />\n * {showDownloadButton ? (\n * <Button pressHandler={() => Updates.fetchUpdateAsync()} text=\"Download and run update\" />\n * ) : null}\n * <StatusBar style=\"auto\" />\n * </View>\n * );\n * }\n * ```\n */\nexport const useUpdates: () => UseUpdatesReturnType = () => {\n const [updatesState, setUpdatesState] = useState<UseUpdatesStateType>(defaultUseUpdatesState);\n\n // Change the state based on native state machine context changes\n useEffect(() => {\n getNativeStateMachineContextAsync()\n .then((context) => {\n setUpdatesState((updatesState) => reduceUpdatesStateFromContext(updatesState, context));\n })\n .catch((error) => {\n // Native call can fail (e.g. if in development mode), so catch the promise rejection and surface the error\n setUpdatesState((updatesState) => ({ ...updatesState, initializationError: error }));\n });\n const subscription = addUpdatesStateChangeListener((event) => {\n setUpdatesState((updatesState) => reduceUpdatesStateFromContext(updatesState, event.context));\n });\n return () => subscription.remove();\n }, []);\n\n // Return the updates info and the user facing functions\n return {\n currentlyRunning,\n ...updatesState,\n };\n};\n"]}