Last active
January 10, 2022 17:06
-
-
Save dudeinthemirror/b25eb8cf0b71aa07003f4e7d17decf83 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Higher Order Component for CodePush | |
// ----------------------------------- | |
// in a file called utils/withCodePush.ts | |
// ----------------------------------- | |
import React from 'react'; | |
import CodePush from 'react-native-code-push'; | |
export const codePushSync = () => { | |
CodePush.sync({ | |
installMode: CodePush.InstallMode.IMMEDIATE, | |
}); | |
}; | |
const withCodePush = (app: React.FC) => { | |
codePushSync(); | |
const options = { | |
checkFrequency: CodePush.CheckFrequency.ON_APP_START, | |
installMode: CodePush.InstallMode.IMMEDIATE, | |
onerror: (...args: any[]) => { | |
// log CodePush error to e.g. Loggly, BugSnag, etc | |
}, | |
}; | |
return CodePush(options)(app); | |
}; | |
export default withCodePush; | |
// ----------------------------------- | |
// in a top level file (e.g. index.ts) | |
// ----------------------------------- | |
import withCodepush from 'utils/withCodepush'; | |
import { name as appName } from './app.json'; | |
if (__DEV__) { | |
AppRegistry.registerComponent(appName, () => MainApp); | |
} else { | |
AppRegistry.registerComponent(appName, () => withCodepush(MainApp)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment