You can split your CodePush integration as Production and Staging with using
sync
function.
Check below example:
import React, { useEffect } from "react";
import codePush from "react-native-code-push";
const CodePushService = ({ stagingKey, productionKey, testUser }) => {
useEffect(() => {
codePush.notifyAppReady().then(() => {
if (testUser) {
codePush.sync({
deploymentKey: stagingKey,
installMode: codePush.InstallMode.IMMEDIATE,
updateDialog: {
appendReleaseDescription: true,
descriptionPrefix: "\n\nDeveloper Notes:\n\n",
},
});
} else {
codePush.sync({
deploymentKey: productionKey,
rollbackRetryOptions: {
delayInHours: 1, // default is 24
maxRetryAttempts: 3, // default is 1
},
});
}
});
}, [testUser, productionKey, stagingKey]);
return null;
};
export default codePush({ checkFrequency: codePush.CheckFrequency.MANUAL })(
CodePushService
);
You can use the above code like below:
import CodePushService from './CodePushService';
const App = () => {
return(
<>
<CodePushService
stagingKey="xxxxxxxxxxx"
productionKey="xxxxxxxxxx"
testUser={true} // make this part dynamic
/>
</>
);
}