May 20, 2021.
Use app versioning.
The best practice is to automate the versioning so that you don't have to manually set the app version again and again.
The idea is to
- Get the current git SHA, if no older SHA found, store it in the localstorage.
- If older SHA found, compare the SHAs, if not equal, clear the storage, set the new SHA in localstorage.
This will give you the current short version of the current commit SHA.
git rev-parse --short HEAD
In your package.json
scripts:{
start : `REACT_APP_CURRENT_GIT_SHA=`git rev-parse --short HEAD` react-scripts app.js
}
in the code, we get this variable through
process.env.REACT_APP_CURRENT_GIT_SHA
Code:
const APP_VERSION = process.env.REACT_APP_CURRENT_GIT_SHA;
if (typeof localStorage.APP_VERSION === 'undefined' || localStorage.APP_VERSION === null) {
localStorage.setItem('APP_VERSION', APP_VERSION);
}
if (localStorage.APP_VERSION != APP_VERSION) {
localStorage.clear();
}`