Skip to content

Instantly share code, notes, and snippets.

@dudeinthemirror
Last active January 10, 2022 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudeinthemirror/b25eb8cf0b71aa07003f4e7d17decf83 to your computer and use it in GitHub Desktop.
Save dudeinthemirror/b25eb8cf0b71aa07003f4e7d17decf83 to your computer and use it in GitHub Desktop.
// 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