Reputation: 155
I want bring state from first load to second load, without reset state and without Redux, if I Init state before load, then I setState for change to new Value, then I refresh or I re-call component(second load), without my state reset to init state(like first load), is imposible??
Upvotes: 0
Views: 110
Reputation: 509
You can use local storage if you want to use it in the other tabs of the browser too. Use session storage if you just want to store it in the same tab of the browser.
state = {
page_value: localStorage.getItem("page_value") || ''
}
componentWillUnmount(){
window.removeEventListener('onbeforeunload', this.compareValue())
}
compareValue(){
const old_page_value = localStorage.getItem("page_value")
if (this.state.page_value !== old_page_value){
localStorage.setItem("page_value", this.state.page_value)
}
}
Upvotes: 1