A class helps to trigger callback functions by history traversal
npm install --save bf-lifecycle
import BackForwardLifecycle from 'bf-lifecycle';
let data;
const bfLifecycle = new BackForwardLifecycle({
callback: () => {
data = 'bfcache';
},
storeState: () => {
sessionStorage.setItem('data', 'nobfcache');
},
restoreState: () => sessionStorage.getItem('data'),
options: {
hasDependency: true,
withClearScrollWillNotStoreBfCache: true,
},
});
bfLifecycle.mount();
data = bfLifecycle.triggerRestoreState();
See here
<a href="ansrlm.github.io/bf-lifecycle">BF-LIFECYCLE</a>
Soon be added time-expire function on bf-lifecycle v1.1.0
Then bf-lifecycle will support react framework as hook (expect in v2.1.0)
MIT © ansrlm